Files
discord-bot/events/client/interactionCreate.js
Noah Pombas 584afd0fe6 Update 1.0.0
2024-04-21 19:07:51 +02:00

39 lines
1.3 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: `Command doesn't exist!`, 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 (e) {
interaction.reply({ content: e.message });
}
}
}