discord.py delete author message after executing command

六月ゝ 毕业季﹏ 提交于 2020-07-22 21:36:56

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!