【问题标题】:Logging problem when bot deletes messsage Discord.py python 3.9.2bot删除消息Discord.py python 3.9.2时的日志记录问题
【发布时间】:2021-08-11 23:08:49
【问题描述】:

我的 Discord 机器人有一个烦人的问题。我的机器人名为 R3NAUT,它是一个使用 python 3.9.2 和 discord.py 1.6.0 编程的单服务器审核机器人。

问题是,当机器人记录消息删除时,即使我禁止它,它也会记录机器人删除的消息。代码如下:

@Cog.listener()
async def on_message_delete(self, message):
    if not message.author.bot:
        embed = Embed(title="Message deletion",
                    description=f"Deleted by {message.author.display_name} in {message.channel}.",
                    colour=0xff6f00,
                    timestamp=datetime.utcnow())

        fields = [("Content", message.content, False)]

        embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/629382706299666432/837723544863244338/unnamed_3.png")

        for name, value, inline in fields:
            embed.add_field(name=name, value=value, inline=inline)

        await self.logs_channel.send(embed=embed)

当有人键入帮助命令并且机器人被编程为在 60 秒后删除帮助命令时,就会出现此问题。奇怪的是,在日志中,写的是成员删除了消息而不是机器人。 Image how the logged embed looks。如果你想要完整的代码,这里是https://github.com/Guard-SK/R3NAUT/ 谢谢回复。

Guard_SK

【问题讨论】:

  • 您必须添加一个条件。添加:if message.author == client.user: returnclient 这里是 bot 变量。
  • 它到底在哪里显示被删除的机器人消息?,在您提供的图像中,它仅显示您的消息已被删除,而不是机器人的

标签: logging discord discord.py


【解决方案1】:

if not message.author.bot: 检查邮件作者是否是机器人,而不是检查邮件是否被机器人删除。因此,使用此代码,将跳过的唯一消息将是机器人发送的消息

据我所知,跳过机器人删除的消息的唯一方法是从审核日志中获取它们,您可以在下面的审核日志中阅读:

【讨论】:

  • 没有完全按照你的方式做,因为我不知何故做不到,但我用 if message.author.id == BotID: 替换了 if not message.autor.bot:但对于某人来说可能会有所帮助,尤其是当您在 on_message 中按照自己的方式进行操作但我正在执行 cog 命令时
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-07-24
  • 2021-08-14
  • 2020-11-20
  • 2021-10-30
  • 1970-01-01
  • 2019-02-20
  • 2021-04-04
相关资源
最近更新 更多