diff --git a/events/interactionCreate.js b/events/interactionCreate.js index 13132c3..3162603 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -1,4 +1,8 @@ const { Events } = require('discord.js'); +const discordAuth = require('../middleware/discordAuthorization'); + +const { DebugBuilder } = require("../utilities/debugBuilder"); +const log = new DebugBuilder("server", "interactionCreate"); module.exports = { name: Events.InteractionCreate, @@ -8,21 +12,23 @@ module.exports = { const command = interaction.client.commands.get(interaction.commandName); if (!command) { - console.error(`No command matching ${interaction.commandName} was found.`); + log.ERROR(`No command matching ${interaction.commandName} was found.`); return; } log.DEBUG(`${interaction.member.user} is running '${interaction.commandName}'`); - 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 this command!', ephemeral: true }); - } else { - await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); + await discordAuth.authorizeCommand(interaction, command, () => { + try { + command.execute(interaction); + } catch (error) { + log.ERROR(error); + if (interaction.replied || interaction.deferred) { + interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true }); + } else { + interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); + } } - } + }); }, }; \ No newline at end of file