#Create a message tha deletes itself after X seconds

1 messages · Page 1 of 1 (latest)

verbal bison
#

Hello! Im creating a message that my bot sends whenever its mentioned and it auto deletes after 20 seconds, but i dont know how to do it. Here's my code:

@bot.event
async def on_message(msg):
  if bot.user.mentioned_in(msg):

    rebed = discord.Embed(
      title=f'Hello, {msg.author}',
      description=f'Hello, I\'m {bot.user}!\nI am a bot to request and output keys for Roblox executors.\nWant to request a key to our staff? Use `/request` to start!',
      color=discord.Color.blurple()
    )

    rebed.set_thumbnail(url=bot.user.avatar)
    rebed.set_footer(text=f'{bot.user.display_name}, {datetime.datetime.now().strftime('%H:%M, %d/%m/%Y')}.')

    autodel = await msg.reply(embed=rebed)

    autodel.delete_after(20)

I asked Google Gemini how to do it but when I mention the bot the command to delete it raises this error:

  File "C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\client.py", line 400, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\user\VSCode\Python\Keybot\Keybot.py", line 36, in on_message
    autodel.delete_after(20)
    ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Message' object has no attribute 'delete_after'

Can anyone help me with this?

winter cargo
#

Its not a method.

verbal bison
#

oh

winter cargo
#

Read the docs. Don't use AI.

verbal bison
#

sorry :/

velvet crystal
#

if you ever use AI, use claude
But yes, dont use AI, learn the stuff yourself

verbal bison
#

ill search for it. Thanks!

#

got it.

time.sleep(20)

await autodel.delete()

if there is another way to do it without time lib, idk (i dont know too much Python or the library, sry)

earnest cedar
#

msg.reply(embed=rebed, delete_after=20)
time.sleep will block your code and will not work.
I recommend learning python first to avoid frustration. It is difficult to help you if you do not know python. Discord bots are not simple projects.
Just a fyi I wont spoonfeed more answers

verbal bison
#

ok.

#

Ty!

narrow hound
winter cargo
narrow hound
#

oh