Discord.py 机器人不阅读其他机器人的消息
Discord.py bot not reading other bot's messages
当我 运行 下面的 python 代码时,它不会接收来自其他机器人的消息:
@bot.event
async def on_message(message):
print(message)
有什么方法可以让我的 discord.py 机器人接收来自其他机器人的消息吗?
由于消息来自机器人,会不会是因为机器人使用了嵌入?因为 discord 无法从嵌入打印消息(也许除非你使用 message.embeds
)检查机器人发送的消息是否是纯文本而不是嵌入
我决定只使用 channel.history(limit=10).flatten()
和 channel.fetch_message(ID)
函数并将它们放在一个循环中,这也适用于我的应用程序。
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)
和 运行 您的代码使用此机器人代替。可能不是在生产中使用的最佳方法,但它是通过另一个 bot
促进测试您的 bot 的好方法
当我 运行 下面的 python 代码时,它不会接收来自其他机器人的消息:
@bot.event
async def on_message(message):
print(message)
有什么方法可以让我的 discord.py 机器人接收来自其他机器人的消息吗?
由于消息来自机器人,会不会是因为机器人使用了嵌入?因为 discord 无法从嵌入打印消息(也许除非你使用 message.embeds
)检查机器人发送的消息是否是纯文本而不是嵌入
我决定只使用 channel.history(limit=10).flatten()
和 channel.fetch_message(ID)
函数并将它们放在一个循环中,这也适用于我的应用程序。
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)
和 运行 您的代码使用此机器人代替。可能不是在生产中使用的最佳方法,但它是通过另一个 bot
促进测试您的 bot 的好方法