obama-bot/util/commandLoader.js

25 lines
882 B
JavaScript
Raw Permalink Normal View History

2020-11-28 16:38:23 +00:00
const { client, logger } = require('../index');
const fs = require('fs');
const Discord = require('discord.js');
module.exports.commands = new Discord.Collection();
module.exports.run = () => {
for (const file of fs.readdirSync('commands/')) {
if (file.endsWith('.js')) {
try {
const command = require(`../commands/${file}`);
if (!command.meta?.name)
logger.warn(`Command ${file} does not have a 'name' attribute; skipping.`);
else
this.commands.set(command.meta.name, command);
} catch(e) {
logger.error(`Failed to load command '${file}'`);
console.error(e);
process.exit(1);
}
}
}
logger.info(`${this.commands.size} command${this.commands.size != 1 ? 's' : ''} loaded`);
}