Search code examples
javascriptnode.jsdiscord

I am having this " throw new RangeError('BITFIELD_INVALID', bit);" error; and i just can not find the solution


I keep getting this error:

        throw new RangeError('BITFIELD_INVALID', bit);
    ^

RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined.
    at Function.resolve (I:\DiscordManagment\ReactionRolesAnimeHub\node_modules\←[4mdiscord.js←[24m\src\util\BitField.js:152:11)
    at I:\DiscordManagment\ReactionRolesAnimeHub\node_modules\←[4mdiscord.js←[24m\src\util\BitField.js:147:54
    at Array.map (<anonymous>)
    at Function.resolve (I:\DiscordManagment\ReactionRolesAnimeHub\node_modules\←[4mdiscord.js←[24m\src\util\BitField.js:147:40)
    at Client._validateOptions (I:\DiscordManagment\ReactionRolesAnimeHub\node_modules\←[4mdiscord.js←[24m\src\client\Client.js:546:33)
    at new Client (I:\DiscordManagment\ReactionRolesAnimeHub\node_modules\←[4mdiscord.js←[24m\src\client\Client.js:73:10)
    at Object.<anonymous> (I:\DiscordManagment\ReactionRolesAnimeHub\main.js:5:16)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1072:14)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:937:32)←[39m {
  [←[32mSymbol(code)←[39m]: ←[32m'BITFIELD_INVALID'←[39m
}
_____

I have been searching for the messed up and outdated variable but i can not seem to find nor find a solution to this issue. Can someone help me please> This bot's function is to auto add roles to someone when they react to an emoji below the message. For a self role system. I have been at this for a while trying to weed out the bugs. However this is a bug that i can not find the solution for in my code.


const Discord = require('discord.js');


const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.message, Intents.channel, Intents.reaction] });
const prefix = '-';

const fs = require('fs');

client.commands = new Discord.Collection();

const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
    const command = require(`./commands/${file}`);

    client.commands.set(command.name, command);
}


client.on('ready', () => {
    console.log('bot is online!');
});


client.on('message', message => {

    if (!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();
    if (command === 'ping') {
        client.commands.get('ping').excecute(message, args);
    }
    if (command === 'reactionrole') {
        client.commands.get('reactionrole').execute(message, args, Discord, client);
    }

});

client.login('');


module.exports = {
    name: 'reactionrole',
    description: "Sets up a reaction role message!",
    async execute(message, args, Discord, client) {
        const channel = '876575997338742786';
        const extrovertRole = message.guild.roles.cache.find(role => role.name === "Extrovert");
        const introvertRole = message.guild.roles.cache.find(role => role.name === "Introvert");

        const hotFaceEmoji = ':hot_face:';
        const coldFaceEmoji = ':cold_face:';

        let embed = new Discord.MessageEmbed()
            .setColor('#e42643')
            .setTitle('What kind of personality do you havc?')
            .setDescription('Choosing a personality allows people to know how to approach you/n/n'
                + `${hotFaceEmoji} for Extrovert \n`
                + `${coldFaceEmoji} for Introvert`);

        let messageEmbed = await message.channel.send(embed);
        messageEmbed.react(hotFaceEmoji);
        messageEmbed.react(coldFaceEmoji);

        client.on('messageReactionAdd', async (reaction, user) => {
            if (reaction.message.partial) await reaction.message.fetch();
            if (reaction.partial) await reaction.fetch();
            if (user.bot) return;
            if (!reaction.message.guild) return;

            if (reaction.message.channel.id == channel) {
                if (reaction.emoji.name === hotFaceEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(extrovertRole);
                }
                if (reaction.emoji.name === coldFaceEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.add(introvertRole);
                }
            } else {
                return;
            }

        });

        client.on('messageReactionRemove', async (reaction, user) => {

            if (reaction.message.partial) await reaction.message.fetch();
            if (reaction.partial) await reaction.fetch();
            if (user.bot) return;
            if (!reaction.message.guild) return;


            if (reaction.message.channel.id == channel) {
                if (reaction.emoji.name === hotFaceEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.remove(extrovertRole);
                }
                if (reaction.emoji.name === coldFaceEmoji) {
                    await reaction.message.guild.members.cache.get(user.id).roles.remove(introvertRole);
                }
            } else {
                return;
            }
        });
    }

}   

Solution

  • Try replacing the following and see if it works.

    • Replace Intents.message with Intents.FLAGS.GUILD_MESSAGES
    • Replace Intents.channel with Intents.FLAGS.GUILDS
    • Replace Intents.reaction with Intents.FLAGS.GUILD_MESSAGE_REACTIONS

    Refer this in the Discord Documentation for more info. Perhaps, it may help you in finding something else as well.