Taking action after some time. discord.py or disnake

Advertisements

Question:

How can I perform actions after a while? Let’s say: if 60 seconds have passed, then the message is deleted, and something is also deleted in the database.

Possible Solutions:

Make a message delete in the same slash_command, and then use the listener to catch the deleted message and change the database…

If you have better options, please let me know.

Possible Solution Example:

@bot.slash_commands()
async def sell(ctx):
    ctx.send("Bla bla bla", delete_after=60)

@bot.event
async def on_message_delete():
    ...

>Solution :

Well…I am hoping that you are talking about a discord bot or a client here…
For deleting a message after a while you can use the following code:
I am sure that since you have mentioned the usage of a slash command, you would have used the "interaction" parameter in your function but just in case I shall give the code for ctx also…
if ctx:

await ctx.send("your message here", delete_after=60)

or if interaction:

await interaction.response.send_message("your message here", delete_after=60)

in the meanwhile you may have a listener going on as such:

@bot.event
async def on_message_delete(message):
    message_content=message.content

you can do any required functions with the message_content…
Hope this helps you!

Leave a ReplyCancel reply