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

升级discord.js v14时Intent配置报错:Cannot read properties of undefined

解决discord.js v14中GatewayIntentBits.FLAGS未定义的错误

这个错误的核心原因是discord.js v14重构了意图常量的结构——移除了GatewayIntentBits.FLAGS这个嵌套层级,所有意图常量直接挂载在GatewayIntentBits对象下。

你只需要把代码里的GatewayIntentBits.FLAGS.XXX改成GatewayIntentBits.XXX即可,修改后的完整客户端代码如下:

const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildBans,
        GatewayIntentBits.GuildIntegrations,
        GatewayIntentBits.GuildWebhooks,
        GatewayIntentBits.GuildInvites,
        GatewayIntentBits.GuildVoiceStates,
        GatewayIntentBits.GuildPresences,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildMessageReactions,
        GatewayIntentBits.GuildMessageTyping,
        GatewayIntentBits.DirectMessages,
        GatewayIntentBits.DirectMessageReactions,
        GatewayIntentBits.DirectMessageTyping,
    ],
    partials: ["CHANNEL", "GUILD_MEMBER", "MESSAGE", "REACTION", "USER"],
    allowedMentions: {
        parse: ['users', 'roles'],
        repliedUser: false
    }
});

client.setMaxListeners(0)

module.exports = client;

另外需要确认你的discord.js确实已经更新到v14版本:

  • 执行npm list discord.js查看当前安装版本
  • 如果版本不对,重新执行npm install discord.js@latest强制更新,同时清理npm缓存避免旧版本残留

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 19:06:18