discord-handler.js
Version:
A simple Discord.js command & event handler with support for slash, message, and categories.
21 lines (17 loc) • 695 B
JavaScript
const fs = require("fs");
const path = require("path");
module.exports = (client) => {
const eventsPath = process.cwd() + "/events";
if (!fs.existsSync(eventsPath)) return;
const files = fs.readdirSync(eventsPath).filter(file => file.endsWith(".js"));
for (const file of files) {
const event = require(path.join(eventsPath, file));
if (event && event.name && typeof event.run === "function") {
if (event.once) {
client.once(event.name, (...args) => event.run(client, ...args));
} else {
client.on(event.name, (...args) => event.run(client, ...args));
}
}
}
};