Discord.js最新版本中Intents.FLAGS报错问题求助
问题分析与解决
报错原因
你的报错是因为Discord.js v14+版本已移除Discord.Intents.FLAGS写法,同时代码存在几个明显错误:
- 导入了
GatewayIntentBits却未使用,反而调用已废弃的Discord.Intents.FLAGS - 定义的客户端变量是
client,后续监听事件却用了未声明的bot intents参数里多嵌套了一层方括号,语法错误
修正后的代码
const { Client, GatewayIntentBits } = require('discord.js') const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] }); client.once('ready', () => { console.log('Bot is ready!'); }); // 记得补充机器人登录代码 client.login('你的机器人令牌');
关键修改点
- 改用Discord.js v14+标准写法:
GatewayIntentBits.xxx替代旧的Discord.Intents.FLAGS.xxx - 保持变量名一致:全程使用
client,避免混用未定义的bot - 移除
intents数组内多余的嵌套方括号,直接传入意图枚举值组成的数组
内容的提问来源于stack exchange,提问作者SasniySas
相关产品推荐
相关产品推荐

