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

Discord.js v14 Intents配置报错求助(Node.js v19.3.0)

解决Discord.js最新版Intents配置错误问题

错误原因分析

你遇到的两个错误都是因为最新版Discord.js(v14及以上)彻底改变了Intents的使用方式,旧的Intents构造函数和Intents.ALL属性已经被移除:

  • TypeError: Cannot read properties of undefined (reading 'ALL'):v14+里没有Intents.ALL这个快捷属性,且你未正确导入新的Intent对象。
  • TypeError: Intents is not a constructor:v14+已废弃Intents构造函数,改用GatewayIntentBits枚举类。

正确配置方法

1. 导入正确的Intent对象

从discord.js中导入GatewayIntentBits,替代旧的Intents:

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

2. 明确指定所需的Intents

最新版Discord.js要求手动声明机器人需要的Intent,不能使用全量的ALL(Discord已限制无差别Intent的使用)。根据机器人功能选择对应Intent,比如基础聊天机器人需要的配置:

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds, // 服务器相关操作必备
    GatewayIntentBits.GuildMessages, // 接收服务器内消息
    GatewayIntentBits.MessageContent // 读取消息内容(需在开发者门户开启特权意图)
  ]
});

如果需要基础默认的Intent集合,可使用GatewayIntentBits.Default,再追加额外需要的Intent:

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

3. 开启特权网关意图

如果机器人用到MessageContent、GuildMembers或PresenceIntent,必须登录Discord开发者门户,找到你的机器人应用,在「Privileged Gateway Intents」板块开启对应开关,否则代码会报错或无法正常工作。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 11:02:07