我正在为我的服务器制作一个服务器机器人,我想记录所有的消息删除和编辑。它将登录到一个日志通道,供员工查看。在日志通道中,我想让消息显示被删除的内容、消息编辑之前的内容以及编辑消息之后的内容。我怎样才能机器人显示被删除或编辑的消息?
@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)
发布于 2020-07-31 21:23:05
你可以在使用的时候使用on_message_delete和on_message_edit,然后你应该给函数消息而不是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)
@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)
发布于 2021-06-09 05:12:39
在写这篇文章时,上面显示的方法将不起作用。这就是我编辑它的原因。
这行代码:
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
https://stackoverflow.com/questions/63182846
复制相似问题