Reputation: 47
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
Upvotes: 2
Views: 21311
Reputation: 31
I'm kinda late here. I tried implementing this with the new 1.0 terms but couldn't make it work. If anyone has an updated version, please do tell
Edit: I found that the new best way of doing it is to just add this at the end of the function:
await ctx.message.delete()
No need for a separate delete function anymore.
Upvotes: 3
Reputation: 60944
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')
Upvotes: 1