So i have made a command $mute @name which basically mutes a player when typed. But what i want is when i type the command , after 5 or 10 seconds the command input line that is $mute @name get removed from the chat .
2 Answers
That would mean that you would have to wait for 5-10 seconds after the command, and then delete it. Just make sure your bot has permissions to delete messages:
@client.command()
async def mute(ctx, member: discord.Member):
muted_role = ctx.guild.get_role(YOUR_ROLE_ID) # Make sure not to put it in a string
await member.add_roles(muted_role)
await asyncio.sleep(5) # Make sure you import asyncio, also change the 5 to whatever seconds you would like
await ctx.message.delete()
The code above will give the user the Muted
role (whichever role you specify via the id of that role) and will give that role to the member. Then it will wait 5 seconds (you can change this to whatever you would like) and then delete the command message.

- 1,667
- 9
- 27
Here are two methods you could use.
The first way would be to use await asyncio.sleep
using the asyncio
import. The reason we don't use time.sleep
would be because this would be a blocker. A blocker means that if you use this command in one place, you would stop the entire bot and no one else would be able to use commands until it's done. An example would be as below:
import asyncio
@client.command()
async def test(ctx):
await ctx.message.delete() # deletes message sent by user
# do some things here
msg = await ctx.send("done")
await asyncio.sleep(5) # waits for 5 seconds
await msg.delete() # deletes message sent by bot, aka 'done'
The second way would be to use delete_after
assuming you're only deleting the bot's message. I wasn't able to get the direct link to the docs, but they say:
delete_after (float) – If provided, the number of seconds to wait in the background before deleting the message we just sent. If the deletion fails, then it is silently ignored.
The example is as follows:
@client.command()
async def test2(ctx):
await ctx.send("done", delete_after=5)
Some other referral links:
- SO: How to make a bot delete its own message after 5 seconds
- SO: Discord.py How can I make a bot delete messages after a specific amount of time
- SO: Deleting a bot's message in discord.py
Note: Both of these commands have been tested, and both commands work as expected.

- 2,326
- 3
- 12
- 36