1

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():
    ...
Deprool
  • 75
  • 8
  • You can also use `asyncio.sleep()` to wait for a while. However, why would you want to use a listener to catch the message deletion? You're the one that's deleting it, you already have all the info available...? – stijndcl Jan 24 '23 at 15:00
  • I just need to delete the message after some event, and perform some action – Deprool Jan 24 '23 at 15:06
  • But if you are the one deleting the message, why do you need to wait for the event? Can't you perform the action after deleting it in that command? – stijndcl Jan 24 '23 at 16:18

1 Answers1

0

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!