So I have likes 6 folder on my bot commands, meanwhile I need to manually add "the folder name" into the command.js (so bot can run the command on those folders) but when I add more than 4 folder name in the code, it said "Cannot read properties of undefined (reading 'name'), meanwhile if it's only 4 or less it works fine, is there a way so the bot can run those folders without adding the name into handlers ?
here's my folder that I had currently : https://i.stack.imgur.com/KrO0J.png
here's the error after I add more than 4 folders on the handler : https://i.stack.imgur.com/XYClm.png
and here's the code I use for the command handler:
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));
};
};
["mod", "utility", "misc", "department"].forEach(x => load(x));
};