执行node main.js后Discord Bot无法上线的故障排查求助
解决Discord Bot启动时的TypeError错误
错误根源:你使用的discord.js版本是v14.3.0,该版本已移除Discord.Intents.FLAGS写法,改用GatewayIntentBits定义网关意图,因此出现读取FLAGS时未定义的报错。
修复步骤:
- 修改main.js里的意图定义代码,将
Discord.Intents.FLAGS替换为Discord.GatewayIntentBits - 意图名称保持不变,仅归属对象变更
修改后的完整main.js代码:
const Discord = require('discord.js'); const client = new Discord.Client({ intents: [ Discord.GatewayIntentBits.Guilds, Discord.GatewayIntentBits.GuildMessages ] }); client.once('ready', () => { console.log('GhxstedCloudz is online'); }); client.login('my bot token');
额外注意:若你的Bot需要读取消息内容,需在Discord开发者门户的Bot设置中开启消息内容特权(Message Content Intent),否则无法获取消息内容。
内容的提问来源于stack exchange,提问作者Undefined
相关产品推荐
相关产品推荐

