Moved all handlers into one file
This commit is contained in:
@@ -4,7 +4,7 @@ const fs = require('fs');
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadSlashCommands(client) {
|
||||
function loadSlashCommandsEvents(client) {
|
||||
const cmdPath = path.join(__dirname, '..', '..', 'commands');
|
||||
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
@@ -60,4 +60,4 @@ function loadSlashCommands(client) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { loadSlashCommands }
|
||||
module.exports = { loadSlashCommandsEvents }
|
||||
|
||||
@@ -4,7 +4,7 @@ const fs = require('fs');
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadContextMenu(client) {
|
||||
function loadContextMenuEvents(client) {
|
||||
const contextMenuPath = path.join(__dirname, '..', '..', 'commands-contextmenu');
|
||||
const contextMenuFiles = fs.readdirSync(contextMenuPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
@@ -44,4 +44,4 @@ function loadContextMenu(client) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { loadContextMenu }
|
||||
module.exports = { loadContextMenuEvents }
|
||||
|
||||
24
utils/eventHandlers/events.js
Normal file
24
utils/eventHandlers/events.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadEvents(client) {
|
||||
const serverDir = path.join(__dirname, '..', '..', 'events', 'server')
|
||||
const eventDirs = fs.readdirSync(serverDir)
|
||||
for (const eventDir of eventDirs) {
|
||||
const eventFiles = fs.readdirSync(path.join(serverDir, eventDir))
|
||||
for (const eventFile of eventFiles) {
|
||||
const eventPath = path.join(serverDir, eventDir, eventFile)
|
||||
const event = require(eventPath)
|
||||
if ('name' in event && 'execute' in event && 'event' in event && event.type === 'event') {
|
||||
client.on(event.event, event.execute)
|
||||
} else {
|
||||
console.log(`[WARNING] The event at ${eventPath} is missing a required "name", "execute", "type" or "event" property.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = { loadEvents }
|
||||
@@ -1,23 +0,0 @@
|
||||
const { Events } = require('discord.js')
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadInteractionEvents(client) {
|
||||
const interactionsPath = path.join(__dirname, '..', '..', 'events', 'interactions')
|
||||
const interactionsFiles = fs.readdirSync(interactionsPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
for (const file of interactionsFiles) {
|
||||
const filePath = path.join(interactionsPath, file);
|
||||
const interactionFile = require(filePath);
|
||||
|
||||
if ('name' in interactionFile && 'execute' in interactionFile && interactionFile.type === 'interaction') {
|
||||
client.on(Events.InteractionCreate, interactionFile.execute)
|
||||
} else {
|
||||
console.log(`[WARNING] The interactions event at ${filePath} is missing a required "name", "execute" or "type" property.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { loadInteractionEvents }
|
||||
@@ -1,24 +0,0 @@
|
||||
const { Events } = require('discord.js')
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadMessageEvents(client) {
|
||||
const messagePath = path.join(__dirname, '..', '..', 'events', 'messages');
|
||||
const messageFiles = fs.readdirSync(messagePath).filter(file => file.endsWith('.js'));
|
||||
|
||||
for (const file of messageFiles) {
|
||||
|
||||
const filePath = path.join(messagePath, file);
|
||||
const message = require(filePath);
|
||||
|
||||
if (message.type === 'message') {
|
||||
client.on(Events.MessageCreate, message.execute);
|
||||
} else {
|
||||
console.log(`[WARNING] The message at ${filePath} is missing a required "type" property.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { loadMessageEvents }
|
||||
@@ -1,22 +0,0 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
/** @param { import('discord.js').Client } client */
|
||||
|
||||
function loadOtherEvents(client) {
|
||||
const otherPath = path.join(__dirname, '..', '..', 'events', 'other')
|
||||
const otherFiles = fs.readdirSync(otherPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
for (const file of otherFiles) {
|
||||
const filePath = path.join(otherPath, file);
|
||||
const other = require(filePath);
|
||||
|
||||
if ('name' in other && 'execute' in other && 'event' in other && other.type === 'other') {
|
||||
client.on(other.event, other.execute)
|
||||
} else {
|
||||
console.log(`[WARNING] The other event at ${filePath} is missing a required "name", "execute", "type" or "event" property.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { loadOtherEvents }
|
||||
@@ -1,23 +0,0 @@
|
||||
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 }
|
||||
Reference in New Issue
Block a user