如果用户编辑消息,如何仍然删除它们(python discord bot)

时间:2021-05-03 05:41:45

标签: python discord discord.py bots

所以我有一个 python discord bot,它用于删除包含某些特定内容的用户消息。这是代码的简化版本:

@bot.event
async def on_message(ctx):
    if ctx.content == "some content":
        await ctx.delete()
    else:
        await bot.process_commands(ctx)

所以现在的问题是现在有一些聪明人,他们先发送另一条消息,然后立即编辑它并写下机器人应该在那里删除的内容。问题是,机器人不会监视编辑过的消息。有没有办法做到这一点?

2 个答案:

答案 0 :(得分:1)

您可以使用 discord.on_message_edit(before, after)discord.on_raw_message_edit(payload)。以下是它们的官方 API 参考以及如何使用它:https://discordpy.readthedocs.io/en/latest/api.html#discord.on_message_edit

答案 1 :(得分:1)

您可以使用 on_message_edit 事件检查它。

@bot.event
async def on_message_edit(before, after):
    if after.content == "some content":
        await after.delete()