Discord.js V13升级指南及启动报TypeError错误的解决方法
Discord.js V13 启动 Client 报错修复方案
问题场景
升级使用Discord.js V13版本运行机器人时,每次启动都会触发报错,原有主文件代码如下:
const { Discord, Intents } = require('discord.js'); const client = new Discord.Client({ partials: ["CHANNEL","MESSAGE","REACTION"], intents: [Intents.ALL] });
报错信息:
const client = new Discord.Client({ ^ TypeError: Cannot read properties of undefined (reading 'Client')
报错原因
- 错误对discord.js库本身执行解构赋值操作,Discord并非discord.js导出的子属性
- V13版本已废弃
Intents.ALL配置,无需引入全部Intents,仅需配置机器人实际使用的Intents即可
修复代码
const Discord = require('discord.js'); const client = new Discord.Client({ partials: ["CHANNEL","MESSAGE","REACTION"], intents: [ Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.GUILD_INVITES, Discord.Intents.FLAGS.GUILD_MEMBERS, Discord.Intents.FLAGS.GUILD_PRESENCES ] });
内容的提问来源于stack exchange,提问作者JustShush
相关产品推荐
相关产品推荐

