diff --git a/events/client/ready.js b/events/client/ready.js new file mode 100644 index 0000000..41e98a9 --- /dev/null +++ b/events/client/ready.js @@ -0,0 +1,6 @@ +module.exports = { + name: 'ready', + async execute() { + console.log('bot ready!'); + }, +}; \ No newline at end of file diff --git a/events/interactions/interactionCreate.js b/events/interactions/interactionCreate.js new file mode 100644 index 0000000..4831733 --- /dev/null +++ b/events/interactions/interactionCreate.js @@ -0,0 +1,23 @@ +module.exports = { + name: 'interactionCreate', + async execute(interaction, client) { + + if (!interaction.isCommand() || !client.commands.has(interaction.commandName)) return; + + const command = client.commands.get(interaction.commandName); + + if (!command) return; + + try { + await command.execute(interaction); + } + catch (error) { + console.error(error); + await interaction.reply({ + content: 'A error occur while trying to execute the command.\n```' + error + '```', + ephemeral: true, + }); + } + + }, +}; \ No newline at end of file diff --git a/index.js b/index.js index 8a3e2e8..4f2dd2d 100644 --- a/index.js +++ b/index.js @@ -23,8 +23,8 @@ for (const folder of commandFolders) { for (const file of commandFiles) { - const cmd = require(`./commands/${folder}/${file}`); - commands.push(cmd.data.toJSON()); + const command = require(`./commands/${folder}/${file}`); + commands.push(command.data.toJSON()); } } @@ -46,30 +46,28 @@ const rest = new REST({ version: '9' }).setToken(token); catch (error) { console.error(error); } + })(); -client.on('ready', async () => { +const eventFolders = fs.readdirSync('./events'); - console.log('Bot ready!'); +for (const folder of eventFolders) { -}); + const eventFiles = fs.readdirSync(`./events/${folder}`).filter(file => file.endsWith('.js')); -client.login(token); + for (const file of eventFiles) { -client.on('interactionCreate', async interaction => { + const event = require(`./events/${folder}/${file}`); - if (!interaction.isCommand() || !client.commands.has(interaction.commandName)) return; + if(event.once) { + client.once(event.name, (...args) => event.execute(...args, client)); + } + else { + client.on(event.name, (...args) => event.execute(...args, client)); + } - const command = client.commands.get(interaction.commandName); - - if(!command) return; - - try { - await command.execute(interaction); - } - catch (error) { - console.error(error); - await interaction.reply({ content: 'A error occur while trying to execute the command.\n```' + error + '```', ephemeral: true }); } -}); \ No newline at end of file +} + +client.login(token); \ No newline at end of file