Discord.py机器人未读取其他机器人的消息

时间:2019-08-16 21:27:53

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

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

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

有什么方法可以使我的discord.py机器人从其他机器人中提取消息?

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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)

并使用此机器人运行您的代码。可能不是在生产中使用的最佳方式,但它是通过另一个机器人促进对您的机器人进行测试的好方法

相关问题