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,24 @@
const { Events } = require('discord.js')
const path = require('path');
const fs = require('fs');
/** @param { import('discord.js').Client } client */
function loadModalEvents(client) {
const modalPath = path.join(__dirname, '..', '..', 'events', 'modals');
const modalFiles = fs.readdirSync(modalPath).filter(file => file.endsWith('.js'));
for (const file of modalFiles) {
const filePath = path.join(modalPath, file);
const modal = require(filePath);
if ('name' in modal && 'execute' in modal && modal.type === 'modal') {
client.on(Events.InteractionCreate, modal.execute);
} else {
console.log(`[WARNING] The modal at ${filePath} is missing a required "name", "execute" or "type" property.`);
}
}
}
module.exports = { loadModalEvents }