From 170f7437f84435918e78673e9332fee460f30125 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 26 Feb 2021 21:25:07 -0700 Subject: [PATCH] fix directoried command loading --- handle/command.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/handle/command.js b/handle/command.js index e122baf..e220376 100644 --- a/handle/command.js +++ b/handle/command.js @@ -5,17 +5,19 @@ const chalk = require('chalk'); module.exports = client => { let commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); - fs.readdirSync('./commands').filter(file => !file.includes('.')).forEach(dir => fs.readdirSync(`./commands/${dir}`).filter(file => file.endsWith('.js')).forEach(x => commands.push(x))); + let dirSet = new Map(); + fs.readdirSync('./commands').filter(file => !file.includes('.')).forEach(dir => fs.readdirSync(`./commands/${dir}`).filter(file => file.endsWith('.js')).forEach(x => {commands.push(x); dirSet.set(x, dir)})); //console.log(''); //let cora = ora(`${chalk.white("Loading commands into client.")} ${chalk.blue("[")}${chalk.blueBright("0")}${chalk.blue("/")}${chalk.blueBright(`${commands.length}`)}${chalk.blue("]")}`).start(); //let num = 0; + commands.sort(); console.log(`\n${chalk.gray('[BOOT]')} >> ${chalk.blue('Getting Commands...')}\n`); for (let commandf of commands) { //num++; //cora.text = `${chalk.white("Loading commands into client.")} ${chalk.blue("[")}${chalk.blueBright(`${num}`)}${chalk.blue("/")}${chalk.blueBright(`${commands.length}`)}${chalk.blue("]")}`; - if (Object.keys(require.cache).includes(require.resolve(`../commands/${commandf}`))) {delete require.cache[require.resolve(`../commands/${commandf}`)];} - var command = require(`../commands/${commandf}`); + if (Object.keys(require.cache).includes(require.resolve(`../commands/${dirSet.has(commandf) ? `${dirSet.get(commandf)}/`: ''}${commandf}`))) {delete require.cache[require.resolve(`../commands/${commandf}`)];} + var command = require(`../commands/${dirSet.has(commandf) ? `${dirSet.get(commandf)}/`: ''}${commandf}`); client.commands.set(command.name, command); if (command.aliases) {command.aliases.forEach(a => client.aliases.set(a, command.name));} console.log(`${chalk.gray('[LOAD]')} >> ${chalk.blueBright('Loaded Command')} ${chalk.white(command.name)} ${chalk.blueBright('with')} ${chalk.white(command.aliases && command.aliases.length ? command.aliases.length : 0)} ${chalk.blueBright('aliases')}`);