Files
Emmelia-Link-Flayer-Rewrite/events/interactionCreate.js
Logan Cusano 14fac69ab7 Add functionality to create transactions
- Transactions work against the account balance
- Needs helper functions for users
- Needs more testing
2023-02-26 03:26:24 -05:00

38 lines
1.4 KiB
JavaScript

const { Events } = require('discord.js');
const { authorizeCommand } = require('../middleware/discordAuthorization');
const { authorizeTokenUsage } = require('../middleware/balanceAuthorization');
const { DebugBuilder } = require("../utilities/debugBuilder");
const log = new DebugBuilder("server", "interactionCreate");
module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);
if (!command) {
log.ERROR(`No command matching ${interaction.commandName} was found.`);
return;
}
log.DEBUG(`${interaction.member.user} is running '${interaction.commandName}'`);
await authorizeCommand(interaction, command, async () => {
await authorizeTokenUsage(interaction, command, async () => {
try {
if (command.deferInitialReply || !interaction.options.getBool('public')) await interaction.deferReply({ ephemeral: true });
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 });
}
}
})
});
},
};