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



输入图片描述

我正在尝试创建我自己的不和谐机器人,它给了我错误,我不知道该怎么做它给了我错误

输入图片描述

你能帮我一下吗?我的discord.js版本是14.0.3我的node.js版本是18.5.0

我尝试了一切,我可以甚至你的提示,我不能这样做,所以你有任何提示请帮助我,因为我答应了一个朋友,我会帮助他

我得说这是第一次发生在我身上,在那之前我创造了两个机器人

discord.jsv14中,Intents已被GatewayIntentBits取代。因此,创建客户端的正确方法如下:

const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
// ...
]
})

更多信息,请访问这里=>Discord.js v13升级到v14时代码中断

他们在discord.js v14中改变了这个工作方式。官方更新指南中的示例:

const { Client, Intents } = require('discord.js'); // old
const { Client, GatewayIntentBits, Partials } = require('discord.js'); // new
const client = new Client({ intents: [Intents.FLAGS.GUILDS], partials: ['CHANNEL'] }); // old
const client = new Client({ intents: [GatewayIntentBits.Guilds], partials: [Partials.Channel] }); // new

如果意图缺失或未正确列出,则会发生此错误。参考这里的代码,它将工作。

const Discord = require('discord.js');
const client = new.Discord.Client({
intents: [
"GUILDS",
"GUILD_MESSAGES"
]
});