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

启动Discord机器人时出现BitFieldInvalid错误求助

解决Discord.js机器人BitFieldInvalid错误(VoiceStates意图相关)

错误原因

这个报错是因为你当前使用的discord.js版本中,GatewayIntentBits.VoiceStates这个枚举值不存在,导致你把undefined传入了意图数组,触发了位字段的合法性校验失败。

修复方案

根据你的discord.js版本,选择对应的正确写法:

若使用discord.js v14及以上版本

先确认当前版本:

npm list discord.js

如果版本是v14+,GatewayIntentBits.VoiceStates的写法是正确的,但可能是依赖安装异常,尝试重新安装依赖:

npm uninstall discord.js
npm install discord.js@latest

若使用discord.js v13版本

v13中该意图的名称为大写的GUILD_VOICE_STATES,修改代码对应行即可:

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GUILD_VOICE_STATES, // 替换原有的VoiceStates
  ],
});

额外注意

别忘了前往Discord开发者后台,给机器人开启Privileged Gateway Intents中的Voice States权限,否则即使代码正确,机器人也无法正常获取语音状态数据。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 17:04:52