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

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 23:24:02