discord.py执行命令后删除作者消息
问题描述:
我需要机器人从命令作者处删除消息,并留下机器人消息。任何帮助将不胜感激!谢谢。
I need the bot to delete the message from the command author, and leave the bot message. Any help will be appreciated! thank you.
我已经尝试在Google上寻找答案,但是没有任何作用
I have already tried looking for a answer on google but nothing has worked
答
您可以通过使用 pass_context
选项将上下文传递给命令来获取调用命令的消息。您可以使用 Client.delete_message
协程删除邮件。
You can obtain the message that called the command by passing the context with the command using the pass_context
option. You can use the Client.delete_message
coroutine to delete messages.
from discord.ext import commands
bot = commands.Bot(command_prefix='!')
@bot.command(pass_context=True)
async def deletethis(ctx):
await bot.say('Command received')
await bot.delete_message(ctx.message)
await bot.say('Message deleted')
bot.run('token')