Encountering issues when starting a Discord bot

I am facing an error when I attempt to launch my Discord bot. The error message is as follows:

throw new DiscordjsRangeError(ErrorCodes.BitFieldInvalid, bit);
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined.

Here is the relevant portion of my code:

const Discord = require('discord.js');
const { Client, GatewayIntentBits } = require('discord.js');
const ytdl = require('ytdl-core');
const ffmpeg = require('fluent-ffmpeg');

const botClient = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.VoiceStates,
  ],
});

It seems that the inclusion of GatewayIntentBits.VoiceStates is causing this issue, but I can’t figure out why it is occurring. Does anyone have insights or solutions? My goal is to create a music bot with warning capabilities.

This error usually arises from using an outdated or incompatible version of the discord.js library. First, ensure that both your discord.js version and Node.js version you’re using are up-to-date as newer intents may not be present in older versions. You can check your discord.js version using npm list discord.js and update it using npm install discord.js@latest. If everything is up-to-date and the issue persists, double-check your GatewayIntentBits import to confirm it’s being imported correctly and is supported by the current library version.

you can try checking your node and npm versions also. sometimes having old or mismatch versions wll cause issues, update them to latest and try again. if you still face problem, try creating a new project with a fresh package.json and copy your code to see if that helps. sometimes a fresh start works wonders!