好的,所以我收到了一个错误消息,该错误消息仅在昨天才生效,并且从无处可破.....
现在这是错误
/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));
};
答案 0 :(得分:0)
好吧,错误是我的项目由于某种原因未保存,所以我搞砸了evrything很好,但我只需要再次保存所有内容即可。
答案 1 :(得分:0)
似乎您未定义name变量,请尝试在代码之前定义它,因为它在错误中返回undefined。