Reputation: 472
I am working on a discord bot in python3 (discord.py 1.3.3, discord 1.0.1) and I have a need to delete a user message, but I can't figure out how to call the coroutine properly.
I have looked at some other threads, and tried reviewing the documentation (and the discord.py docs) but I haven't been able to figure it out.
Here's what I'm testing with:
import discord
from discord.ext import commands
TOKEN = os.getenv('DISCORD_TOKEN')
bot = commands.Bot(command_prefix='!')
@bot.command(name='deleteme', help='testing command for dev use')
async def deleteme(ctx):
msg = ctx.message.id
print(f'DEBUG: message id is {msg}')
await msg.delete
# await ctx.delete(msg, delay=None) #nope
# await ctx.delete_message(ctx.message) #nope
# await bot.delete_message(ctx.message) #nope
# await command.delete_message(ctx.message) #nope
# await discord.Client.delete_message(msg) #nope
Running this returns the console debug message with an ID number, but the message isn't deleted. If I add a debug print line after await msg.delete
it doesn't return. So this tells me where the script is hanging. That said, I still haven't been able to figure out what the proper command should be.
The bots server permissions include "manage messages"
Upvotes: 1
Views: 3704
Reputation: 368
In order to delete a message, you have to use the discord.Message
object, for example, you would do:
await ctx.message.delete()
The delete()
coroutine is a method of discord.Message
Upvotes: 3