From 1c253d25cb1d35aa987d76e07806999c562712d6 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 2 Mar 2025 16:24:26 -0500 Subject: Bringing more features from 2.x; ESLint; API --- bot/src/handlers/command.js | 22 ++++++++++++++++++++++ bot/src/handlers/event.js | 25 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 bot/src/handlers/command.js create mode 100644 bot/src/handlers/event.js (limited to 'bot/src/handlers') diff --git a/bot/src/handlers/command.js b/bot/src/handlers/command.js new file mode 100644 index 0000000..0da2fab --- /dev/null +++ b/bot/src/handlers/command.js @@ -0,0 +1,22 @@ +import { Collection } from 'discord.js'; +import { readdirSync } from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const commandPath = path.join(__dirname, '../commands'); +const commandFiles = readdirSync(commandPath).filter(file => file.endsWith('.js')); + +export async function command(client) { + client.commands = new Collection(); + console.log(`[i] Loading ${commandFiles.length} commands into memory...`); + + for (const file of commandFiles) { + const { default: command } = await import(`../commands/${file}`); + console.log(`[i] Loading command: ${command.data.name}`); + client.commands.set(command.data.name, command); + } +} diff --git a/bot/src/handlers/event.js b/bot/src/handlers/event.js new file mode 100644 index 0000000..b15cbf2 --- /dev/null +++ b/bot/src/handlers/event.js @@ -0,0 +1,25 @@ +import { fileURLToPath } from 'url'; +import { dirname } from 'path'; +import path from 'node:path'; +import fs from 'node:fs'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const eventsPath = path.join(__dirname, '../events'); +const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js')); + +export async function event(client) { + console.log(`[i] Loading ${eventFiles.length} events into memory...`); + for (const file of eventFiles) { + const filePath = path.join(eventsPath, file); + const event = (await import(filePath)).default; + console.log(`[i] Loading event: ${event.name}`); + if (event.once) { + client.once(event.name, (...args) => event.execute(...args)); + } else { + client.on(event.name, (...args) => event.execute(...args)); + } + } + +} -- cgit v1.2.3