【问题标题】:Discord.py bot not reading other bot's messagesDiscord.py 机器人不阅读其他机器人的消息
【发布时间】:2019-12-23 04:09:41
【问题描述】:

当我运行下面的 python 代码时,它不会接收来自其他机器人的消息:

@bot.event
async def on_message(message):
    print(message)

有什么办法可以让我的 discord.py 机器人接收来自其他机器人的消息?

【问题讨论】:

  • 是否触发任何消息?
  • 它触发所有不是来自机器人的消息
  • 您还有其他on_message 活动吗?
  • 不,我没有任何其他 on_message 事件
  • 您能否创建一个最小且完整的示例来重现您的问题?您当前的代码应该适用于您的问题。

标签: python bots discord.py discord.py-rewrite


【解决方案1】:

Discord.py 机器人被设置为忽略其他机器人发送的消息,see the code here - 更具体地说是第 972 和 973 行:

if message.author.bot:
    return

要解决这个问题,您可以对机器人进行子类化,并覆盖 process_commands 方法,如下所示:

class UnfilteredBot(commands.Bot):
    """An overridden version of the Bot class that will listen to other bots."""

    async def process_commands(self, message):
        """Override process_commands to listen to bots."""
        ctx = await self.get_context(message)
        await self.invoke(ctx)

并改为使用此机器人运行您的代码。可能不是在生产中使用的最佳选择,但它是一种便于通过另一个机器人测试你的机器人的好方法

【讨论】:

    【解决方案2】:

    我决定只使用channel.history(limit=10).flatten()channel.fetch_message(ID) 函数并将它们放在一个循环中,这也适用于我的应用程序。

    【讨论】:

      【解决方案3】:

      由于消息来自机器人,可能是因为机器人正在使用嵌入?因为不和谐无法打印来自嵌入的消息(也许除非你使用message.embeds)检查机器人发送的消息是否是纯文本而不是嵌入

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-06
        • 1970-01-01
        • 1970-01-01
        • 2023-02-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-05
        相关资源
        最近更新 更多