【问题标题】:getting the discord.py bot to echo a message and then remove it让 discord.py 机器人回显一条消息,然后将其删除
【发布时间】:2020-02-22 21:04:46
【问题描述】:

基本上我想制作一个机器人,它使用特定命令复制消息,然后删除原始消息并保留自己的消息。 这是我使用的代码

if message.content.startswith("!echo"):
            await message.channel.send(message.content[5:].format(message))
            await client.delete_message(context.message) 

到目前为止,回显效果很好,但原始消息没有被删除

【问题讨论】:

  • 您使用什么版本的 discord.py?因为“client.delete_message”对于重写来说已经过时了,如果你运行的是最新版本,await message.delete() 是删除消息的方法

标签: python discord discord.py


【解决方案1】:

确保您使用的是最新的 discord.py 库。你可以通过python -m pip freeze查看你安装的版本

在 discord.py 1.0 版中,.delete_message 更改为 .delete:
https://discordpy.readthedocs.io/en/latest/migrating.html
https://discordpy.readthedocs.io/en/latest/api.html?highlight=delete#discord.Message.delete

要删除您执行的消息:

if message.content.startswith("!echo"):
  await message.channel.send(message.content[5:].format(message))
  await message.delete()

如果您想在 5 秒后删除该消息,也可以使用 await message.delete(delay=5)。
您的机器人需要有权删除该文本频道中的消息。

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 2021-10-14
    • 2020-11-08
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    • 2018-08-16
    • 1970-01-01
    • 2021-06-11
    相关资源
    最近更新 更多