diff --git a/index.js b/index.js index b5ec6c6..6e06d54 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ // Require the necessary discord.js classes const fs = require('node:fs'); const path = require('node:path'); -const { Client, Collection, Events, GatewayIntentBits } = require('discord.js'); +const { Client, Collection, GatewayIntentBits } = require('discord.js'); const { token } = require('./config.json'); // Create a new client instance @@ -29,35 +29,18 @@ for (const folder of commandFolders) { } } -client.on(Events.InteractionCreate, async interaction => { - if (!interaction.isChatInputCommand()) return; +const eventsPath = path.join(__dirname, 'events'); +const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js')); - console.log(interaction); - - const command = client.commands.get(interaction.commandName); - - if (!command) { - console.error(`No command matching ${interaction.commandName} was found.`); - return; +for (const file of eventFiles) { + const filePath = path.join(eventsPath, file); + const event = require(filePath); + if (event.once) { + client.once(event.name, (...args) => event.execute(...args)); + } else { + client.on(event.name, (...args) => event.execute(...args)); } - - try { - await command.execute(interaction); - } catch (error) { - console.error(error); - if (interaction.replied || interaction.deferred) { - await interaction.followUp({ content: 'There was an error while executing the command!', ephemeral: true }); - } else { - await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); - } - } -}); - -// When the client is ready, run this code (only once) -// We use 'c' for the event parameter to keep it separate from the already defined 'client' -client.once(Events.ClientReady, c => { - console.log(`Ready! Logged in as ${c.user.tag}`); -}); +} // Log in to Discord with your client's token client.login(token); \ No newline at end of file