Joshua Day
Joshua Day

Reputation: 11

How to make a bot delete its own message after 5 seconds

I can't get the bot to delete its own message.

I have tried await ctx.message.delete() and ctx.message.delete(embed)

@bot.command()
async def help(ctx):
    embed=discord.Embed(title="List of commands.", description="", colour=discord.Color.orange(), url="")
    await ctx.send(embed=embed)
    await ctx.message.delete()
    await asyncio.sleep(5)
    await message.delete()

I'm wanting the bot to delete the command then send an embed: "A list of commands has been sent to your DM's" then wait 5 secs and delete the embed

Upvotes: 1

Views: 6213

Answers (1)

XroixHD
XroixHD

Reputation: 161

ctx.message.delete() deletes the message from the user.

But to delete the bot's message you need the bot's message object
from the return of ctx.send() :


bot.remove_command('help') # Removes default help command 

@bot.command()
async def help(ctx):
    embed=discord.Embed(title="List of commands.", description="", colour=discord.Color.orange())
    msg = await ctx.send(embed=embed) # Get bot's message

    await ctx.message.delete() # Delete user's message
    await asyncio.sleep(5)

    await msg.delete() # Delete bot's message

EDIT: You can use parameter delete_after=(float)

await ctx.send(embed=embed, delete_after=5.0)

Upvotes: 4

Related Questions