RavenBot/main/functions/functions.js
2021-04-23 14:20:48 -05:00

30 lines
1.0 KiB
JavaScript

const Discord = require("discord.js");
const fs = require("fs");
const color = JSON.parse(fs.readFileSync(`Storage/color.json`, `utf8`));
module.exports = {
loadCommands: function(bot, dirname) {
fs.readdir(dirname, (err, files) => {
if(err) console.error(err);
var jsFiles = files.filter(f => f.split(".").pop() === "js");
if(jsFiles.length <= 0){
console.log(`No command to load in the folder : ${dirname.replace(/.\/commands\//gi, "")}`);
return;
}
jsFiles.forEach((f, i) => {
delete require.cache[require.resolve(`${dirname}${f}`)];
var props = require(`${dirname}${f}`);
console.log(`${i + 1}: ${f} Loaded`);
bot.commands.set(props.help.name, props);
if(props.help.aliases) for (const alias of props.help.aliases){
bot.aliases.set(alias, props);
}
})
})
},
}