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

16 lines
599 B
JavaScript

const { readdirSync } = require("fs");
const { join } = require("path");
const eventDir = join(__dirname, "..", "events");
module.exports.run = (bot) => {
const eventFiles = readdirSync(eventDir);
for(const eventFile of eventFiles) {
const event = require(`${eventDir}/${eventFile}`);
const eventName = eventFile.split(".").shift();
bot.on(eventName, event.bind(null, bot));
delete require.cache[require.resolve(`${eventDir}/${eventFile}`)];
}
bot.events = eventFiles.length;
console.log(`Loaded ${eventFiles.length} events !`);
}