[英]Discord.py Logging deleted and edited messages
我正在為我的服務器制作一個服務器機器人,我想記錄所有消息刪除和編輯。 它將登錄到一個日志通道供工作人員查看。 在日志頻道中,我想讓消息顯示刪除的內容或消息編輯之前的內容以及消息編輯之后的內容。 我將如何讓機器人顯示已刪除或已編輯的消息?
@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)
您可以在使用時使用on_message_delete和on_message_edit ,然后您應該給出 function 消息而不是 ctx。
@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(channel, 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(channel, embed=embed)
上面顯示的方式在發表這篇文章時不起作用。 這就是為什么我已經編輯它,所以它會。
該行:
embed=discord.Embed(title="{} edited a
message".format(message_before.member.name),
description="", color="Blue")
它不起作用,因為message
沒有屬性member
。 它也不起作用,因為您無法將顏色設置為Blue
或沒有 integer 轉換的字符串。 最好的方法是定義一個像這樣的十六進制輸入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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.