我一直得到这个错误:
throw new RangeError('BITFIELD_INVALID', bit);
^
RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined.
at Function.resolve (I:DiscordManagmentReactionRolesAnimeHubnode_modules←[4mdiscord.js←[24msrcutilBitField.js:152:11)
at I:DiscordManagmentReactionRolesAnimeHubnode_modules←[4mdiscord.js←[24msrcutilBitField.js:147:54
at Array.map (<anonymous>)
at Function.resolve (I:DiscordManagmentReactionRolesAnimeHubnode_modules←[4mdiscord.js←[24msrcutilBitField.js:147:40)
at Client._validateOptions (I:DiscordManagmentReactionRolesAnimeHubnode_modules←[4mdiscord.js←[24msrcclientClient.js:546:33)
at new Client (I:DiscordManagmentReactionRolesAnimeHubnode_modules←[4mdiscord.js←[24msrcclientClient.js:73:10)
at Object.<anonymous> (I:DiscordManagmentReactionRolesAnimeHubmain.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
}
_____
我一直在寻找混乱和过时的变量,但我似乎找不到也找不到解决这个问题的方法。有人能帮我一下吗?这个机器人的功能是,当某人对消息下方的表情符号做出反应时,自动为其添加角色。对于自我角色系统。我做这个已经有一段时间了,试图清除漏洞。然而,这是一个bug,我无法在我的代码中找到解决方案。
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.FLAGS.GUILD_MESSAGES
代替Intents.message
- 用
Intents.FLAGS.GUILDS
代替Intents.channel
- 用
Intents.FLAGS.GUILD_MESSAGE_REACTIONS
代替Intents.reaction
更多信息请参考Discord文档。也许,它也可以帮助你找到其他的东西。
我也有同样的问题,但我使用了这种格式,它对我有效:
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });