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

Discord.js 14如何沿用V13的32767全Intent配置?

Discord.js v14 开启全部意图解决方案

在v14中无法直接沿用v13的32767数值方式配置全意图,但可以通过以下两种方式实现:

方法一:手动枚举所有意图

将GatewayIntentBits下的所有枚举值添加到intents数组中,这种方式清晰可控,适合需要明确知道开启哪些意图的场景:

const { Client, GatewayIntentBits } = require('discord.js');

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildBans,
    GatewayIntentBits.GuildEmojisAndStickers,
    GatewayIntentBits.GuildIntegrations,
    GatewayIntentBits.GuildWebhooks,
    GatewayIntentBits.GuildInvites,
    GatewayIntentBits.GuildVoiceStates,
    GatewayIntentBits.GuildPresences,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.GuildMessageReactions,
    GatewayIntentBits.GuildMessageTyping,
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.DirectMessageReactions,
    GatewayIntentBits.DirectMessageTyping,
    GatewayIntentBits.MessageContent
  ]
});

方法二:自动合并所有意图值

通过Object.values获取所有GatewayIntentBits枚举值,再用按位或操作合并成一个数值,适合快速配置全意图的场景:

const { Client, GatewayIntentBits } = require('discord.js');

// 合并所有意图的数值
const allIntents = Object.values(GatewayIntentBits).reduce((total, bit) => total | bit, 0);

const client = new Client({ intents: allIntents });

关键注意事项

  • 特权意图需手动开启:GuildMembers、GuildPresences、MessageContent属于特权意图,必须登录Discord开发者门户,进入你的机器人应用的「Bot」页面,找到「Privileged Gateway Intents」板块手动开启这些选项,否则机器人无法正常获取对应数据或启动失败。
  • 按需开启更优:虽然全意图配置方便,但建议只开启机器人实际依赖的意图,减少不必要的数据传输,提升机器人性能和稳定性。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 11:22:03