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

Discord.js v14.7.1 Intent配置报错问题求助

Discord.js v14 Intent配置错误解决指南

1. 修正GatewayIntentBits导入与使用方式

你遇到的Cannot read properties of undefined (reading 'GUILDS')错误,大概率是导入或Intent名称拼写错误。Discord.js v14中GatewayIntentBits的属性为驼峰命名(而非v13的全大写),且必须正确导入:

CommonJS语法:

const { Client, GatewayIntentBits } = require('discord.js');

// 实例化Client时传入正确的Intent数组
const client = new Client({
  intents: [
    GatewayIntentBits.Guilds, // 对应原GUILDS权限
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent // 特权Intent,需后台手动启用
  ]
});

ES模块语法:

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

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent
  ]
});

2. 解决ClientMissingIntents错误

这个错误说明代码中声明的Intent不完整,或与后台启用的权限不匹配:

  • 确保代码中包含所有业务需要的Intent:比如要处理服务器事件必须加GatewayIntentBits.Guilds,要读取消息内容必须加GatewayIntentBits.MessageContent
  • 登录Discord开发者后台,在机器人页面的Privileged Gateway Intents区域,开启代码中用到的所有特权Intent(如MessageContent、GuildMembers),保存设置后重启机器人

3. 版本兼容性调整

当前Node.js v19.3.0为非LTS版本,可能存在不稳定兼容问题。建议切换到Node.js v18.x LTS版本(如v18.17.0),Discord.js v14对LTS版本的支持更稳定。

若降级Discord.js后仍无法运行,清理依赖缓存后重新安装:

rm -rf node_modules package-lock.json
npm install

4. 常见排查要点

  • 检查Intent名称拼写:v14中是GatewayIntentBits.Guilds,不是全大写的GUILDS
  • 不要省略核心Intent:Guilds是大多数机器人必备的基础Intent
  • 确认机器人后台的Intent设置已保存,且与代码中的配置完全对应

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 05:15:20