2 回答

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可以在使用時(shí)使用on_message_delete和on_message_edit,然后您應(yīng)該給函數(shù)消息而不是 ctx。
示例on_message_delete:
@client.event
async def on_message_delete(message):
? ? embed=discord.Embed(title="{} deleted a message".format(message.member.name),?
? ? description="", color="Blue")
? ? embed.add_field(name= message.content ,value="This is the message that he has?
? ? deleted",?
? ? inline=True)
? ? channel=client.get_channel(channel_id)
await channel.send(embed=embed)
示例on_message_edit:
@client.event
async def on_message_edit(message_before, message_after):
? ? embed=discord.Embed(title="{} edited a?
? ? message".format(message_before.member.name),?
? ? description="", color="Blue")
? ? embed.add_field(name= message_before.content ,value="This is the message before?
? ? any edit",?
? ? inline=True)
? ? embed.add_field(name= message_after.content ,value="This is the message after the?
? ? edit",?
? ? inline=True)
? ? channel=client.get_channel(channel_id)
await channel.send(embed=embed)

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊
該行:
embed=discord.Embed(title="{} edited a?
? ? message".format(message_before.member.name),?
? ? description="", color="Blue")
它不工作,因?yàn)閙essage沒有屬性member。它也不起作用,因?yàn)槟荒軐㈩伾O(shè)置為Blue或不進(jìn)行整數(shù)轉(zhuǎn)換的字符串。做到這一點(diǎn)的最好方法是定義一個(gè)像這樣的十六進(jìn)制輸入,color=0xFF0000這會(huì)使它變成紅色。
整行改變了:
embed = discord.Embed(title="{} deleted a message".format(message.author.name),
? ? ? ? ? ? ? ? ? ? ? description="", color=0xFF0000)
以下是經(jīng)過編輯的完整兩個(gè)命令。
@client.event
async def on_message_delete(message):
? ? embed = discord.Embed(title="{} deleted a message".format(message.author.name),
? ? ? ? ? ? ? ? ? ? ? ? ? description="", color=0xFF0000)
? ? embed.add_field(name=message.content, value="This is the message that he has deleted",
? ? ? ? ? ? ? ? ? ? inline=True)
? ? channel = client.get_channel(channelid)
? ? await channel.send(channel, embed=embed)
@client.event
async def on_message_edit(message_before, message_after):
? ? embed = discord.Embed(title="{} edited a message".format(message_before.author.name),
? ? ? ? ? ? ? ? ? ? ? ? ? description="", color=0xFF0000)
? ? embed.add_field(name=message_before.content, value="This is the message before any edit",
? ? ? ? ? ? ? ? ? ? inline=True)
? ? embed.add_field(name=message_after.content, value="This is the message after the edit",
? ? ? ? ? ? ? ? ? ? inline=True)
? ? channel = client.get_channel(channelid)
? ? await channel.send(channel, embed=embed)
我會(huì)在您的代碼頂部定義您想要使用的頻道。
logging_channel = channelID
# then at your two commands do this:
global logging_channel
添加回答
舉報(bào)