Search code examples
pythondiscord.pypycord

Python: How to send changing message with discord.py/py-cord?


How can I send a later on changing message?

I tried something like this:

message = bot.get_channel(id).send("deleting in 5s")
time.sleep(5)
message.delete()

But it gives me this error:

AttributeError: 'coroutine' object has no attribute 'edit'

How can I make this work?


Solution

  • send, delete and edit are async functions, remember to use await when calling them.

    channel = bot.get_channel(id)
    message = await channel.send("deleting in 5s")
    time.sleep(5)
    await message.delete()