[英]Edit the last message that the bot sent discord.py
我一直在查看 web,看看如何讓機器人編輯它的最后一條消息。
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
謝謝你的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.