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

如何用Python检测Discord嵌入消息含指定关键词?Bot未识别嵌入排查

Discord Bot无法识别Discohook嵌入消息的排查方案

1. 补全Intent配置

Discord当前要求Bot必须启用message_content意图才能读取消息的嵌入结构,默认的Intents.default()不包含该权限。修改客户端初始化代码:

intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)

同时需在Discord开发者门户的Bot管理页面,开启Message Content Intent权限(路径:应用 → Bot → Privileged Gateway Intents)。

2. 验证消息接收状态

添加日志代码,确认Bot是否接收到Discohook发送的Webhook消息:

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    # 打印消息来源与嵌入数量
    print(f"消息来源:{'Webhook' if message.webhook_id else '普通用户'}, 嵌入数量:{len(message.embeds)}")
    # 原有逻辑...

如果日志显示嵌入数量为0,说明Discohook发送的消息确实未携带嵌入,需检查Discohook的配置是否正确生成了嵌入。

3. 处理空描述的边界情况

若Discohook发送的嵌入未设置描述字段,原代码会触发错误。修改关键词判断逻辑,增加空值校验:

if embed.description and any(keyword in embed.description.lower() for keyword in keywords):

4. 确认Bot频道权限

确保Bot在目标频道拥有读取消息、发送消息的权限,否则无法检测到嵌入或执行@角色操作。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 02:25:51