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

Discord机器人接收私信时messageCreate事件不触发问题排查

私信无法触发Discord机器人messageCreate事件的修复方案

问题根源

你的代码已声明DirectMessages和MessageContent意图,但私信事件仍不触发,主要是两个关键配置遗漏:

1. 开发者门户未启用MessageContent权限

Discord要求机器人必须在开发者后台手动开启Message Content Intent,仅在代码中声明无效:

  • 登录Discord开发者门户,进入你的机器人应用
  • 切换到「Bot」标签页,在「Privileged Gateway Intents」板块开启Message Content Intent

2. Partial配置缺失

当机器人离线时收到的私信会以Partial对象形式存在,当前仅配置CHANNEL partial不足以处理,需添加MESSAGE:

const bot = new Client({
    partials: ["CHANNEL", "MESSAGE"], // 新增MESSAGE partial
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildVoiceStates,
        GatewayIntentBits.GuildMessageReactions,
        GatewayIntentBits.DirectMessages,
        GatewayIntentBits.GuildMessageTyping,
        GatewayIntentBits.DirectMessageTyping
    ]
});

关于旧版事件的说明

你注释的message事件是Discord.js v12及更早版本的API,v14+已完全移除,必须使用messageCreate事件,这部分你的写法是正确的。

验证步骤

修改配置后重启机器人,发送私信测试,console.log('message')应正常输出。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 17:52:18