discord.py on_message_delete获取消息内容

时间:2020-06-17 16:29:00

标签: python discord discord.py

我正在尝试记录删除用户消息的时间,但是在将消息发送到频道时,我看不到消息的实际内容:

@bot.event
async def on_message_delete(message):
    embed1 = discord.Embed(title="Deleted Message!")
    embed1.add_field(name=f"**Msg Was Deleted**", value=f"Someone Has Deleted The Following:\n`{message}`", inline=True)
    embed1.colour = (0x90EE90)
    dele = bot.get_channel(722832289955971183)
    await dele.send(embed=embed1)

1 个答案:

答案 0 :(得分:1)

它吐出来的“垃圾”是消息对象。该对象具有许多您可以访问的属性-请参见参考中的discord.Message对象。

要获取消息的内容,可以使用消息的content属性,如下所示:

@bot.event
async def on_message_delete(message):
    # Code
    embed.add_field(name="..", value=f"Someone has deleted the following:\n{message.content}")
    # Rest of the code

参考: