Updated Logging & Added Auth Middleware

This commit is contained in:
Logan Cusano
2023-02-25 04:08:29 -05:00
parent 6eef72e951
commit f9c57617c7

View File

@@ -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}'`);
await discordAuth.authorizeCommand(interaction, command, () => {
try {
await command.execute(interaction);
command.execute(interaction);
} catch (error) {
console.error(error);
log.ERROR(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
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 });
interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
},
};