![](/img/trans.png)
[英]RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: 3214336
[英]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);
^
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
}
_____
我一直在尋找混亂和過時的變量,但我似乎找不到也找不到解決這個問題的方法。 有人可以幫我嗎> 這個機器人的 function 是在某人對消息下方的表情符號做出反應時自動為其添加角色。 對於自我角色系統。 我一直在努力清除這些錯誤。 但是,這是一個錯誤,我無法在我的代碼中找到解決方案。
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;
}
});
}
}
嘗試替換以下內容,看看它是否有效。
Intents.message
替換為Intents.FLAGS.GUILD_MESSAGES
Intents.channel
替換Intents.FLAGS.GUILDS
Intents.reaction
替換為Intents.FLAGS.GUILD_MESSAGE_REACTIONS
有關詳細信息,請參閱Discord 文檔中的此內容。 也許,它也可以幫助您找到其他東西。
我有同樣的問題,但我使用了這種格式,它對我有用:
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.