Added interaction event handler
This commit is contained in:
@@ -4,6 +4,6 @@ const { loadContextMenu } = require('./eventHandlers/contextmenu.js')
|
||||
const { loadMessageEvents } = require('./eventHandlers/message.js')
|
||||
const { loadModalEvents } = require('./eventHandlers/modal.js')
|
||||
const { loadReadyEvents } = require('./eventHandlers/ready.js')
|
||||
const { loadInteractionEvents } = require('./eventHandlers/interaction.js')
|
||||
|
||||
|
||||
module.exports = { loadSlashCommands, loadButtonEvents, loadContextMenu, loadMessageEvents, loadModalEvents, loadReadyEvents }
|
||||
module.exports = { loadSlashCommands, loadButtonEvents, loadContextMenu, loadMessageEvents, loadModalEvents, loadReadyEvents, loadInteractionEvents }
|
||||
|
||||
23
utils/eventHandlers/interaction.js
Normal file
23
utils/eventHandlers/interaction.js
Normal 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 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 }
|
||||
Reference in New Issue
Block a user