'Edit the last message that the bot sent discord.py
I've been looking around the web to see how I can make the bot edit its last message.
if message.content.lower() == 'edit':
await message.channel.send('testing')
channel = bot.get_channel(message.channel.id)
message = await channel.fetch_message(message.id)
await asyncio.sleep(3)
await message.edit(content="the new content of the message")
But it just raises this
Ignoring exception in on_message
Traceback (most recent call last):
File "/home/runner/FluidLuxuriousCertifications/venv/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 708, in on_message
message = await channel.fetch_message(message.id)
AttributeError: 'NoneType' object has no attribute 'fetch_message'
172.18.0.1 - - [19/Apr/2022 10:39:21] "HEAD / HTTP/1.1" 200 -
I've done this so I can implement a timer feature into my bot and tried this code to test it so it can edit the message as the timer goes down.
Thanks
Solution 1:[1]
I found out the answer finally, I used:
if message.content.startswith('edit'):
test = await message.channel.send('not edited') # Defined message
await asyncio.sleep(2) # Wait 2 seconds
await test.edit(content='Edited') # Edit it
Thanks for your help though.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Lemm1ngs |
