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

Discord机器人无法读取message.content的问题求助

解决Discord机器人无法读取消息内容的问题

你的问题核心是缺少消息内容特权意图的代码声明——discord.js v14开始,message.content的读取需要单独的MessageContent特权意图,即便你在开发者平台开启了所有特权意图,代码里未声明该意图就无法获取消息内容。

修复步骤:

  • 再次确认Discord开发者平台的机器人页面中,Message Content Intent已开启(你提到已启用所有特权意图,可再次核对该选项状态)。
  • 在客户端的intents数组中添加GatewayIntentBits.MessageContent。
  • 清理代码中重复的意图项(重复项不影响功能,但会造成冗余)。

修改后的代码示例:

import {Client, GatewayIntentBits} from 'discord.js';

const token = "token"
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildMessageReactions,
        GatewayIntentBits.GuildMessageTyping,
        GatewayIntentBits.GuildVoiceStates,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildPresences,
        GatewayIntentBits.MessageContent // 新增消息内容特权意图
    ]    
})

client.login(token);

client.on('ready', () => {
    console.log(`Ready and logged on as ${client.user.tag}`);
});

client.on('messageCreate', message => {
    console.log(message.content); // 直接打印消息内容测试
});

修改完成后重启机器人,即可正常读取message.content的内容。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 05:30:20