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

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 22:37:03