试图通过它的forEach()函数拟合来解决重复动作。 CONSOLE.LOG提供期望的结果,但不是自己的代码。你能解释为什么它不是工作?
const bot = new Discord.Client({disableEveryone: true});
const cmdHandler = ["commands","automation"];
const fileSys = require("fs");
cmdHandler.forEach((v, y) => {
bot.v = new Discord.Collection();
console.log(v);
fileSys.readdir(`./${v}/`, (error, file) => {
if(error) console.log(error);
let jsfile = file.filter(f => f.split (".").pop() === "js")
if(jsfile.length <= 0){
console.log("Couldn't find the commands.");
return
}
jsfile.forEach((f, i) => {
let props = require(`./${v}/${f}`);
console.log(`${f} loaded.`);
bot.v.set(props.help.name, props);
});
});
});
let fullCmd = msg.content.substr(prefixlen);
let splitCmd = fullCmd.split(" ");
let mainCmd = splitCmd[0];
let args = splitCmd.slice(1);
// Set variable for directory content called from ./commands
let commandFile = bot.commands.get(mainCmd);
// execute "run" section of command
if(commandFile){
commandFile.run(bot,msg,args);
无法读取属性“得到”的未定义