【问题标题】:Discord.js returns an undefined error when creating a ClientDiscord.js 在创建客户端时返回未定义的错误
【发布时间】:2021-12-12 08:29:57
【问题描述】:

我按照官方 discord.js 指南中的示例进行操作,并给出了代码:

// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.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);

但是在运行时它给出了这个错误:

D:\DiscCoin\node_modules\discord.js\src\managers\GuildManager.js:39
    if (!cacheWarningEmitted && this._cache.constructor.name !== 'Collection') {
                                                        ^

TypeError: Cannot read properties of undefined (reading 'name')
    at new GuildManager (D:\DiscCoin\node_modules\discord.js\src\managers\GuildManager.js:39:57)
    at new Client (D:\DiscCoin\node_modules\discord.js\src\client\Client.js:127:19)
    at Object.<anonymous> (D:\DiscCoin\index.js:6:16)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

除了遵循官方指南之外,我没有做任何事情。我可能做错了什么?

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    这个错误是前几天在Discord.JS Github上提出来的,原来是@discordjs/collection的回归(link to the comment

    一位维护者建议运行this

    npm i @discordjs/collection

    如果这不起作用,您可以尝试删除您的 node_modules 文件夹并重新安装模块。

    【讨论】:

    猜你喜欢
    • 2021-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-26
    • 2021-02-27
    • 2019-06-22
    相关资源
    最近更新 更多