Search code examples
pythonbotsdiscord.py

How to make discord.py bot delete its own message after some time?


I have this code in Python:

import discord
client = commands.Bot(command_prefix='!')

@client.event
async def on_voice_state_update(member):
    channel = client.get_channel(channels_id_where_i_want_to_send_message))
    response = f'Hello {member}!'
    await channel.send(response)

client.run('bots_token')

And I want the bot to delete its own message. For example, after one minute, how do I do it?


Solution

  • There is a better way than what Dean Ambros and Dom suggested, you can simply add the key-word argument delete_after in .send

    await ctx.send('whatever', delete_after=60.0)
    

    reference