Files
discord-bot/events/client/interactionCreate.js
2025-02-13 04:42:11 +01:00

39 lines
1.2 KiB
JavaScript

const { InteractionType } = require('discord.js');
module.exports = {
name: 'interactionCreate',
/**
* @param {CommandInteraction} interaction
* @param {Client} client
*/
async execute(interaction, client) {
if (interaction.type !== InteractionType.ApplicationCommand) return;
const command = client.slash.get(interaction.commandName);
if (!command) return interaction.reply({content: `❌ Error processing this command.`, ephemeral: true });
if(command.ownerOnly) {
if(interaction.user.id !== client.config.ownerID) {
return interaction.reply({content: `❌ Permission denied`, ephemeral: true })
}
}
const args = [];
for (let option of interaction.options.data) {
if (option.type === 'SUB_COMMAND') {
if(option.name) args.push(option.name);
option.options?.forEach(x => {
if(x.value) args.push(x.value);
});
} else if (option.value) args.push(option.value);
}
try {
command.run(client, interaction, args)
} catch (error) {
interaction.reply({ content: error.message })
}
}
}