升级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
相关产品推荐
相关产品推荐

