繁体   English   中英

编辑机器人发送的最后一条消息 discord.py

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM