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

discord.js运行报CLIENT_MISSING_INTENTS错误,已配intents仍报错如何解决?

问题排查及修复方案

核心错误原因

代码存在3个直接导致intents不生效的逻辑问题:

  • 同时创建了两个客户端实例:bot是无参数初始化的Discord.Client()实例,client是带intents配置的实例,但后续绑定ready事件、调用login方法使用的是未配置intents的bot实例,自然触发缺少intents的报错
  • 初始化client实例时直接调用new Client(),未从Discord对象上引用Client类,运行时会额外抛出Client is not defined错误
  • 若使用discord.js v14及以上版本,intents的配置位置、枚举值规则均有变更,当前配置写法仅兼容v13版本

修复代码

discord.js v13 版本适配

const Discord = require('discord.js');
// 全局仅初始化一个带配置的客户端实例即可
const bot = new Discord.Client({ 
    disableMentions: "everyone",
    ws: {
        intents: ["GUILDS", "GUILD_MEMBERS", "GUILD_MESSAGES", "GUILD_PRESENCES"]
    }
})

const token = 'my token';

bot.on('ready', () =>{
    console.log('This bot is online!')
})

bot.login(token)

discord.js v14 及以上版本适配

const { Client, GatewayIntentBits } = require('discord.js');
const bot = new Client({ 
    disableMentions: "everyone",
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildPresences,
        // 如需读取消息内容,需额外添加以下intent,同时在Discord开发者后台开启对应特权权限
        GatewayIntentBits.MessageContent
    ]
})

const token = 'my token';

bot.on('ready', () =>{
    console.log('This bot is online!')
})

bot.login(token)

注意事项

  • GUILD_MEMBERS、GUILD_PRESENCES、MESSAGE_CONTENT属于敏感权限类intent,需要先在Discord开发者后台对应机器人的「Privileged Gateway Intents」板块开启对应开关,否则启动后仍会报错
  • 不要重复初始化客户端实例,全局维护单实例即可

内容的提问来源于stack exchange,提问作者Resetti

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 10:57:02