Search code examples
pythondiscord.pynextcord

How to make a bot delete a message sent from itself


I have a Discord bot and I want it to delete a "Loading..." message. However it just deletes the user message for the command

@client.command()
async def run(ctx):
    await ctx.send("Loading...")
    await ctx.message.delete()
    await ctx.send("Loading Complete!")

This raises insufficient permissions as it is trying to delete the user message instead of the message it just sent.

What am I doing wrong here?


Solution

  • You can use the delete_after parameter which specifies after how much seconds the message will be deleted after sending.

    await ctx.send("Loading...", delete_after=3) #deleting after 3 seconds