[英]how to fix the Invalid Bitfield discord.js bot crash Problem
代码显示无效位域并且不知道如何修复它,我认为意图很好并且我认为一切都应该正常。 我曾尝试将来自机器人的代码与某人发送的片段结合起来,也许这就是为什么这不起作用
代码:
const { Client, Intents, Message} = require('discord.js');
const util = require('minecraft-server-util');
const {EmbedBuilder} = require('discord.js');
const options = {
timeout: 1000 * 5,
enableSRV: true
};
const prefix = "!mcstatus";
const client = new Client({
intents: [
"Guilds",
"GuildMessages",
"MessageContent"
]
});
client.on('ready', () => {
console.log('bot started');
client.user.setPresence({ activities: [{ name: `${server_ip}`, type: 'WATCHING' }], status: 'active' });
});
const server_ip = "mc.hypixel.net";
const server_port = 25565;
client.on('messageCreate', (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
if(message.content.startsWith(prefix)){
util.status(server_ip, server_port, options)
.then((result) => {
const embed = new EmbedBuilder()
let args = message.content.split(" "); // Splitting with a blank space.
args = args.slice(1); // Remove the first argument which would be the command itself.
const server_port = 25565; // Leave the default port for MC servers.
if (args.length < 1) return message.reply("Didn't provide arguments.")
// Run a forEach loop for every argument.
args.forEach((arg) => {
util
.status(arg, server_port, options)
.then((result) => {
const embed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle("Results")
.setDescription(
`This will show the status and info about the minecraft server \n **Server ip:** ${arg} \n **Server port:** ${server_port}`
)
.addFields(
{ name: "Server Version", value: `${result.version.name}` },
{
name: "Server Protocol Version",
value: `${result.version.protocol}`,
},
{ name: "Players Online", value: `${result.players.online}` },
{ name: "Max Players", value: `${result.players.max}` },
{
name: "MOTD (May Not Display Accurately)",
value: `${result.motd.clean}`,
},
{ name: "Latency", value: `${result.roundTripLatency}` }
)
.setTimestamp();
message.channel.send({ embeds: [embed] });
})
.catch((error) => {
const embed = new EmbedBuilder()
.setColor("#808080")
.setTitle("Error")
.setDescription(
`${arg} was unable to be pinged or you mis-typed the info`
)
.setTimestamp();
message.channel.send({ embeds: [embed] });
});
});
message.channel.send({embeds: [embed]})
})}});
日志 我试过用谷歌搜索东西,但我找不到任何对我有帮助的东西
RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: Guilds.
at Intents.resolve (C:\Users\jason\Desktop\discord minecraft bot test 2\node_modules\discord.js\src\util\BitField.js:152:11)
at C:\Users\jason\Desktop\discord minecraft bot test 2\node_modules\discord.js\src\util\BitField.js:147:54
at Array.map (<anonymous>)
at Intents.resolve (C:\Users\jason\Desktop\discord minecraft bot test 2\node_modules\discord.js\src\util\BitField.js:147:40)
at Client._validateOptions (C:\Users\jason\Desktop\discord minecraft bot test 2\node_modules\discord.js\src\client\Client.js:550:33)
at new Client (C:\Users\jason\Desktop\discord minecraft bot test 2\node_modules\discord.js\src\client\Client.js:76:10)
at Object.<anonymous> (C:\Users\jason\Desktop\discord minecraft bot test 2\index.js:9:16)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32) {
[Symbol(code)]: 'BITFIELD_INVALID'
}
Node.js v18.12.1
PS C:\Users\jason\Desktop\discord minecraft bot test 2>
首先,请参阅有关如何使用 intents 的指南。 (真的好用!)
这看起来也不像 DJSv14 代码。 v14 片段也可以在指南中找到。
要解决您的问题,您可以像这样在实例化新客户端时更改定义意图的方式;
const { GatewayIntentBits } = require('discord.js');
// ...
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
],
});
OT:较新的 D.JS 版本有应用程序命令,我强烈建议你使用那些而不是前缀命令!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.