I'm trying to make a discord bot receive this error [Symbol(code)]: 'BITFIELD_INVALID'

Viewed 70

Following is the code snippet I am trying:

const Discord = require("discord.js");
const client = new Discord.Client({intents:["GUILD_VOICE_STATES","VOICE_STATE_UPDATE"]});
const config = require("./config.json");

client.login(config.token);
2 Answers

From the guide

To enable your intents,

const client = new Client({ intents: [Intents.FLAGS.GUILD_VOICE_STATES] });

You will also have to require the Intents class,

const { Discord, Intents } = require("discord.js");

Most importantly however, "VOICE_STATE_UPDATE" is not an intent, its an event that can only be received with the GUILD_VOICE_STATE intent

VOICE_STATE_UPDATE is not a valid intent. The GUILD_VOICE_STATES is what you want (you have this but VOICE_STATE_UPDATE is invalid). These are the intents you should have to track voice states:

  • GuildMember intents
  • Voice states

Therefore this is how you should declare client

const client = new Discord.Client({
  intents: [
    "GUILD_VOICE_STATES",
    "GUILDS",
    "GUILD_MEMBERS"
  ]
})
//GUILDS is required for some other intents like messages and members
Related