const command = args.shift().slice(config.prefix.length);
//my subfolders (i.e: modules)
// These are the folder names in the command directory
let cmdFile = require(../Commands/${command}
);
//add more subfolders
console.log([command-execute] The command ${command} has been executed by ${msg.author.tag} in ${msg.guild.name}
)
if (!cmdFile) {
return;
}
if (cmdFile) {
cmdFile(bot, msg, args).catch(err => {
const error = new Discord.RichEmbed()
.setTitle(command)
.setDescription(Sorry about this!
)
.addField(Here's what returned
, “" + err + "
”, false)
.setFooter(Contact a developer to fix this
)
.setColor(0xf45c42)
msg.channel.send(error)
console.error(`On execution of ` + command + `in ` + msg.guild.name + `, something went wrong: ` + err)
});
}
Hi right now for example if i do *hug (where * is the prefix) it will find the command in …/Commands but the hug command is in an sub folder like this …/Commands/(some folder)/hug, i want to automate the (folder) so it cycles in all the folders located in …/Commands and finds where the command hug is located,
thank you
@Atom-Dragon - like based on the command name, assuming that the command name and file name are same?
Ok i put the hug command in a sub folder say emotions
so the location is …/Command/emotions/hug now when a person run the command it only checks for it in …/Command/ now i have many sub folders one for mod, utils etc i want it to auto find the hug command i tried doing it like this
var stuff = [‘utils’,‘mod’,‘emotions’]
let cmdFile = require(`../Commands/${command}` && '../Commands/${stuff}/${command}');
where command is hug…etc
but it doesn’t cycle it does cannot find module in …/Command/utils,mod,emotions/hug
Why not declare it as a new variable?
let emotionCmd = require(`../Commands/${stuff}/${command}`)
doesn’t work it still say this
UnhandledPromiseRejectionWarning: Error: Cannot find module '../Commands/mod,utills/ban'
the let stuff = ['mod','utills']
wont cycle it takes it as one as in stuff is /mod,utills/
Here is something that might work…
function filterStuff(stuff, command) {
for (let i=0; i < stuff.length; i++) {
try {
let file = require("../Commands/" + stuff[i] + "/" + command + ".js"
return file;
} catch(e) {
//No command found in category.
}
}
return "No command found.";
}
Any errors? What doesn’t work?
one error is that return file;
it says that an ; is expected
My bad… I forgot some parenthesis. 
function filterStuff(stuff, command) {
for (let i=0; i < stuff.length; i++) {
try {
let file = require("../Commands/" + stuff[i] + "/" + command + ".js");
return file;
} catch(e) {
//No command found in category.
}
}
return "No command found.";
}
it say file is not defined