亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Discord.py 記錄刪除和編輯的消息

Discord.py 記錄刪除和編輯的消息

森林海 2023-04-18 17:36:14
我正在為我的服務器制作一個服務器機器人,我想記錄所有消息的刪除和編輯。它將登錄到一個日志通道供工作人員查看。在日志通道中,我想讓消息顯示被刪除的內容或消息編輯之前的內容以及消息編輯之后的內容。我將如何讓機器人顯示已刪除或已編輯的消息?@client.event()async def on_message_delete(ctx):    embed=discord.Embed(title="{} deleted a message".format(member.name), description="", color="Blue")    embed.add_field(name="What the message was goes here" ,value="", inline=True)    channel=client.get_channel(channel_id)    await channel.send(channel, embed=embed)
查看完整描述

2 回答

?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

您可以在使用時使用on_message_delete和on_message_edit,然后您應該給函數消息而不是 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)


查看完整回答
反對 回復 2023-04-18
?
慕的地8271018

TA貢獻1796條經驗 獲得超4個贊

該行:


embed=discord.Embed(title="{} edited a?

? ? message".format(message_before.member.name),?

? ? description="", color="Blue")

它不工作,因為message沒有屬性member。它也不起作用,因為您不能將顏色設置為Blue或不進行整數轉換的字符串。做到這一點的最好方法是定義一個像這樣的十六進制輸入,color=0xFF0000這會使它變成紅色。


整行改變了:


embed = discord.Embed(title="{} deleted a message".format(message.author.name),

? ? ? ? ? ? ? ? ? ? ? description="", color=0xFF0000)

以下是經過編輯的完整兩個命令。


@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)

我會在您的代碼頂部定義您想要使用的頻道。


logging_channel = channelID

# then at your two commands do this:

global logging_channel


查看完整回答
反對 回復 2023-04-18
  • 2 回答
  • 0 關注
  • 344 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號