编辑bot发送的最后一条消息



我一直在网上寻找如何让机器人编辑它的最后一条消息。

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")

但是它只是引出了这个

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 -

我已经这样做了,所以我可以实现一个定时器功能到我的机器人,并尝试这段代码来测试它,所以它可以编辑消息作为定时器下降。

感谢

我终于找到了答案。我使用:

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

谢谢你的帮助。

最新更新