Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Taking action after some time. discord.py or disnake

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading