【发布时间】:2020-10-28 02:35:16
【问题描述】:
嗨,我正在做一个不和谐的机器人。我几乎结束了,但是当我去运行机器人时,我得到了标题上的错误。
代码:
fs.readdir("./commands/", (err, files) => {
if(err) console.log(err)
let jsfile = files.filter(f => f.split(".").pop() === "js")
if(jsfile.length <= 0) {
return console.log("[LOGS] Couldn't Find Commands!");
}
jsfile.forEach((f, i) => {
let pull = require(`./commands/${f}`);
bot.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(alias => {
bot.aliases.set(alias, pull.config.name)
});
});
});
错误:
TypeError: Cannot read property 'name' of undefined
at C:\Users\ayman\Desktop\test\index.js:28:38
at Array.forEach (<anonymous>)
at C:\Users\ayman\Desktop\test\index.js:26:12
at FSReqCallback.oncomplete (fs.js:158:23)
如果有人能给我留下正确的代码或表格。
【问题讨论】:
-
您确定为您的所有文件设置了
pull.config.name吗?可以分享./commands目录下的其中一个JS文件吗? -
我不知道怎么做。我刚开始编写机器人程序,所以我不知道很多事情。
标签: javascript node.js discord discord.js