无法让 Discord.js示例代码正常工作



尽管我尽力了,但我不明白为什么这个基本的示例代码不起作用。我是Java脚本的新手。我不明白为什么GatewayIntentBits.Guilds行抛出错误。当我评论这句话时,它开始很好。以下是我尝试运行的内容和错误消息。我对这个极其基本的问题感到抱歉;我觉得自己很笨。有人能给我解释一下吗?我看了一遍文件,还没有找到答案。

// Require the necessary discord.js classes
const { Client, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
// Create a new client instance
const client = new Client({ intents: [
GatewayIntentBits.Guilds
] });
// When the client is ready, run this code (only once)
client.once('ready', () => {
console.log('Ready!');
});
// Login to Discord with your client's token
client.login(token);
const client = new Client({ intents: [GatewayIntentBits.Guilds,] });
^
TypeError: Cannot read property 'Guilds' of undefined
at Object.<anonymous> (C:UsersJoshuaprojectSpaceCivBotindex.js:6:57)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47

我不知道到底发生了什么,但我决定卸载Discord.js,然后使用npm重新安装,现在它可以工作了。谢谢你帮我。一切看起来都是正确的。

卸载/重新安装就在后面,将其关闭并重新打开。🤷‍♂️

最新更新