【问题标题】:I am having this " throw new RangeError('BITFIELD_INVALID', bit);" error; and i just can not find the solution我有这个“ throw new RangeError('BITFIELD_INVALID', bit);”错误;我只是找不到解决方案
【发布时间】:2021-10-18 02:41:05
【问题描述】:

我不断收到此错误:

        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
}
_____

我一直在寻找混乱和过时的变量,但我似乎找不到也找不到解决这个问题的方法。有人可以帮我吗> 这个机器人的功能是当某人对消息下方的表情符号做出反应时自动添加角色。对于自我角色系统。我已经有一段时间试图清除这些错误了。然而,这是一个我无法在我的代码中找到解决方案的错误。


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;
            }
        });
    }

}   

【问题讨论】:

  • 查看错误堆栈at Object.&lt;anonymous&gt; (I:\DiscordManagment\ReactionRolesAnimeHub\main.js:5:16)。看起来错误在const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.message, Intents.channel, Intents.reaction] });

标签: javascript node.js discord


【解决方案1】:

尝试替换以下内容,看看是否有效。

  • Intents.message 替换为Intents.FLAGS.GUILD_MESSAGES
  • Intents.channel 替换为Intents.FLAGS.GUILDS
  • Intents.reaction 替换为Intents.FLAGS.GUILD_MESSAGE_REACTIONS

请参阅Discord Documentation 以获取更多信息。也许,它也可以帮助您找到其他东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-23
    • 2020-09-03
    • 2019-03-09
    • 2022-12-04
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 2023-03-18
    相关资源
    最近更新 更多