Moved event handlers to seperate files

This commit is contained in:
2023-11-18 18:42:32 +01:00
parent 4621abe01c
commit 1befe97f90
11 changed files with 316 additions and 213 deletions

View File

@@ -0,0 +1,23 @@
const { Events } = require('discord.js')
const path = require('path');
const fs = require('fs');
/** @param { import('discord.js').Client } client */
function loadReadyEvents(client) {
const readyPath = path.join(__dirname, '..', '..', 'events', 'ready')
const readyFiles = fs.readdirSync(readyPath).filter(file => file.endsWith('.js'));
for (const file of readyFiles) {
const filePath = path.join(readyPath, file);
const ready = require(filePath);
if ('name' in ready && 'execute' in ready && ready.type === 'ready') {
client.on(Events.ClientReady, ready.execute)
} else {
console.log(`[WARNING] The ready event at ${filePath} is missing a required "name", "execute" or "type" property.`);
}
}
}
module.exports = { loadReadyEvents }