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

discord.js中GUILDS Intent报错问题求助

Discord机器人BitFieldInvalid错误解决方法

你遇到的RangeError [BitFieldInvalid]: Invalid bitfield flag or number: GUILDS错误,核心原因是Discord.js版本(大概率是v14及以上)的Intent使用规则变更了,旧版直接写字符串的方式不再兼容。

修正后的代码:

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
    allowedMentions: {
        parse: ['users', 'roles'],
        repliedUser: true
    },
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildPresences,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildMessageReactions
    ],
});
client.on('ready', () => {
    console.log('我准备好了')
});
client.login("你的机器人TOKEN")

关键说明:

  • Discord.js v14起,Intent必须从GatewayIntentBits枚举中调用,不能直接写全大写的字符串(比如原代码里的"GUILDS"),枚举内的名称采用驼峰命名格式(如Guilds对应旧版的GUILDS)
  • GuildMembers和GuildPresences属于特权Intent,需要登录Discord开发者后台,在机器人页面的"Privileged Gateway Intents"板块开启这两个权限,否则机器人无法正常获取成员和在线状态相关数据

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.26 03:16:06