Discord.js: TypeError: 无法读取未定义的属性(读取 'FLAGS')



我的代码很好,一切都很好,但我遇到了一个错误。

我的代码:

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
client.user.setPresence({ activities: [{ name: 'Discord' }], status: 'idle' });
});
client.login(process.env.token);

错误:

TypeError: Cannot read properties of undefined (reading 'FLAGS')
at Object.<anonymous> (/home/runner/discordjs-bot/index.js:5:47)
at Module._compile (node:internal/modules/cjs/loader:1101:14)

有什么帮助吗

在discord.js v14中,Intents导入不存在。相反,在客户端中声明意图时需要使用GatewayIntentBits。一个例子是这样的:

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

最新更新