问题
I need the bot to delete the message from the command author, and leave the bot message. Any help will be appreciated! thank you.
I have already tried looking for a answer on google but nothing has worked
回答1:
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')
来源:https://stackoverflow.com/questions/49352368/discord-py-delete-author-message-after-executing-command