You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

discord.py中机器人为何不响应其他机器人账号的命令?

解决discord.py机器人无法响应其他机器人命令的问题

discord.py的commands.Bot默认会忽略来自其他机器人账号的消息,这就是第二个机器人无法响应第一个机器人命令的原因——虽然on_message事件能接收机器人消息,但命令框架的内置过滤规则会跳过这些消息。

要关闭这个设置,只需要在初始化commands.Bot时添加ignore_bots=False参数即可:

修改后的代码如下:

import discord
from discord.ext import commands

prefix = '.'
intent = discord.Intents.default()
intent.message_content = True
client = commands.Bot(
    command_prefix=prefix,
    intents=intent,
    activity=discord.Game(' .help'),
    ignore_bots=False  # 关闭忽略机器人消息的默认设置
)

@client.command()
async def test(ctx):
    print("ah")

添加这个参数后,第二个机器人就会处理所有机器人账号发送的命令消息了。如果需要更精准的控制(比如只允许特定机器人触发命令),可以额外在命令的检查函数或on_message事件中添加判断逻辑。

内容的提问来源于stack exchange,提问作者993 1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 05:34:53