【问题标题】:TypeError: Cannot read property 'name' of undefined discord.js command handlerTypeError:无法读取未定义 discord.js 命令处理程序的属性“名称”
【发布时间】:2020-09-07 05:50:46
【问题描述】:

好的,所以我收到了一个错误,这在昨天才起作用,但它突然坏了.....

现在是错误

/app/handlers/command.js:8
            bot.commands.set(pull.config.name, pull);
                                         ^
TypeError: Cannot read property 'name' of undefined
at load (/app/handlers/command.js:8:42)
at /app/handlers/command.js:12:75
    at Array.forEach (<anonymous>)
at module.exports (/app/handlers/command.js:12:62)
at /app/index.js:16:72
    at Array.forEach (<anonymous>)
at Object.<anonymous> (/app/index.js:16:33)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)

每个命令都用

打开
module.exports = {
config: {
name: "command name"

现在是命令处理程序中的代码

const { readdirSync } = require("fs")

module.exports = (bot) => {
    const load = dirs => {
        const commands = readdirSync(`./commands/${dirs}/`).filter(d => d.endsWith('.js'));
        for (let file of commands) {
            let pull = require(`../commands/${dirs}/${file}`);
            bot.commands.set(pull.config.name, pull);
            if (pull.config.aliases) pull.config.aliases.forEach(a => bot.aliases.set(a, pull.config.name));
          };
        };
        ["currency", "fun", "holiday", "info", "moderation"].forEach(x => load(x));
};

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    看起来你可能没有定义 name 变量,尝试在代码之前定义它,因为它在错误中返回 undefined。

    【讨论】:

      【解决方案2】:

      好的,错误是我的项目由于某种原因没有保存,所以我搞砸了一切都很好,但我只需要重新保存所有内容。

      【讨论】:

        猜你喜欢
        • 2020-10-11
        • 1970-01-01
        • 2021-02-16
        • 2022-08-04
        • 2021-06-26
        • 2021-12-06
        • 2021-11-13
        • 2022-01-14
        相关资源
        最近更新 更多