gpt4 book ai didi

javascript - Discord.js:无效的位域标志或数字:GUILDS

转载 作者:行者123 更新时间:2023-12-05 02:27:41 25 4
gpt4 key购买 nike

我第一次尝试制作 Discord 机器人。代码非常基础,只是一个在启动时将自己的标签记录到控制台的机器人:

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

const TOKEN = "REDACTED"

const client = new Discord.Client({
intents: ["GUILDS", "GUILD_MESSAGES"]
})

client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}`)
})

client.login(TOKEN)

但是,在 VSCode 终端中输入 node index.js 后,出现以下错误:

PS C:\Users\15055\Documents\Alt Formatter> node index.js
C:\Users\15055\Documents\Alt Formatter\node_modules\discord.js\src\util\BitField.js:168
throw new RangeError(ErrorCodes.BitFieldInvalid, bit);
^

RangeError [BitFieldInvalid]: Invalid bitfield flag or number: GUILDS.
at IntentsBitField.resolve (C:\Users\15055\Documents\Alt Formatter\node_modules\discord.js\src\util\BitField.js:168:11)
at C:\Users\15055\Documents\Alt Formatter\node_modules\discord.js\src\util\BitField.js:163:54
at Array.map (<anonymous>)
at IntentsBitField.resolve (C:\Users\15055\Documents\Alt Formatter\node_modules\discord.js\src\util\BitField.js:163:40)
at Client._validateOptions (C:\Users\15055\Documents\Alt Formatter\node_modules\discord.js\src\client\Client.js:481:41)
at new Client (C:\Users\15055\Documents\Alt Formatter\node_modules\discord.js\src\client\Client.js:78:10)
at Object.<anonymous> (C:\Users\15055\Documents\Alt Formatter\index.js:9:16)
at Module._compile (node:internal/modules/cjs/loader:1112:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
at Module.load (node:internal/modules/cjs/loader:988:32) {
[Symbol(code)]: 11
}

Node.js v18.4.0

我已经使用命令 npm i discord.js 安装了 discord.js,所以我使用的是 v14。

最佳答案

在 discord.js v14 中,意图标志可从 GatewayIntentBits 获得。

const { Client, GatewayIntentBits } = require('discord.js');

const client = new Discord.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
]
})

变更列表:

<表类="s-表"><头>v12/v13v14<正文> GUILDS GatewayIntentBits.Guilds GUILD_BANS GatewayIntentBits.GuildBans GUILD_EMOJIS_AND_STICKERS GatewayIntentBits.GuildEmojisAndStickers GUILD_INTEGRATIONS GatewayIntentBits.GuildIntegrations GUILD_INVITES GatewayIntentBits.GuildInvites GUILD_MEMBERS GatewayIntentBits.GuildMembers GUILD_MESSAGE_REACTIONS GatewayIntentBits.GuildMessageReactions GUILD_MESSAGE_TYPING GatewayIntentBits.GuildMessageTyping GUILD_MESSAGES GatewayIntentBits.GuildMessages GUILD_PRESENCES GatewayIntentBits.GuildPresences GUILD_SCHEDULED_EVENTS GatewayIntentBits.GuildScheduledEvents GUILD_VOICE_STATES GatewayIntentBits.GuildVoiceStates GUILD_WEBHOOKS GatewayIntentBits.GuildWebhooks DIRECT_MESSAGES GatewayIntentBits.DirectMessages DIRECT_MESSAGE_TYPING GatewayIntentBits.DirectMessageTyping DIRECT_MESSAGE_REACTIONS GatewayIntentBits.DirectMessageReactions不适用 GatewayIntentBits.MessageContent

关于javascript - Discord.js:无效的位域标志或数字:GUILDS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73018560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com