Discord.py-如果提到特定用户,如何删除消息

时间:2020-07-14 06:28:41

标签: discord.py discord.py-rewrite

我正在尝试创建一个on_message事件,如果提到管理员,它将删除该消息,然后告诉他们他们不能这样做。这是我的代码

@bot.event
async def on_message(message):
admin_id = "<@496186362886619138>"
    if admin_id in message.content:
        await message.delete()
        await message.channel.send("You can't do that")
    await bot.process_commands(message)

1 个答案:

答案 0 :(得分:2)

再看一下文档,发现mentioned_in()Client.fetch_user()。 我的最终代码如下:

@bot.event
async def on_message(message):
        # DELETE ADMIN MENTION
    user = await bot.fetch_user(496186362886619138)
    if user.mentioned_in(message):
        await message.delete()
        await message.channel.send("You can't do that")
    await bot.process_commands(message)