Files
url-shortener-public/functions/utilities/reloadCommands.js
T
2023-11-03 21:12:55 +01:00

29 lines
1.1 KiB
JavaScript

const included = require("../../requires")
// Here you can add functions that will be run at each startup of the bot
module.exports = {
name:"reloadCommands",
async function(msg, args){
commands.clear()
var path = `${__dirname}/../../functions`
var folders = fs.readdirSync(path).filter(function (file) {
return fs.statSync(path+'/'+file).isDirectory();
});
folders.forEach(element => {
var commandFiles = fs.readdirSync(`${path}/${element}`).filter(file => file.endsWith('.js') && !file.startsWith("index"));
for (const file of commandFiles) {
delete require.cache[require.resolve(`${path}/${element}/${file}`)];
try {
const command = require(`${path}/${element}/${file}`);
commands.set(command.name, command);
} catch (error) {
console.log(error);
}
}
});
// commands.get("garbage_collector").function() // reset garbage collector
console.log(`Reloading ${commands.size} modules done`)
}
}