import { Events, Interaction, ChatInputCommandInteraction, AutocompleteInteraction, ButtonInteraction } from 'discord.js' import { playerButtons, playerEdit } from '../../utils/player' export default { name: Events.InteractionCreate, async execute(interaction: Interaction) { //if (!interaction.isAutocomplete() && !interaction.isChatInputCommand() && !interaction.isButton()) return console.error(`Interaction ${interaction.commandName} is not a command.`) if (interaction.isChatInputCommand()) { interaction = interaction as ChatInputCommandInteraction let chatInputCommand = interaction.client.commands.get(interaction.commandName) if (!chatInputCommand) return console.error(`No chat input command matching ${interaction.commandName} was found.`) console.log(`Command '${interaction.commandName}' launched by ${interaction.user.tag}`) try { await chatInputCommand.execute(interaction) } catch (error) { console.error(`Error executing ${interaction.commandName}:`, error) } } else if (interaction.isAutocomplete()) { interaction = interaction as AutocompleteInteraction let autoCompleteRun = interaction.client.commands.get(interaction.commandName) if (!autoCompleteRun) return console.error(`No autoCompleteRun matching ${interaction.commandName} was found.`) console.log(`AutoCompleteRun '${interaction.commandName}' launched by ${interaction.user.tag}`) try { await autoCompleteRun.autocompleteRun(interaction) } catch (error) { console.error(`Error autocompleting ${interaction.commandName}:`, error) } } else if (interaction.isButton()) { interaction = interaction as ButtonInteraction let button = interaction.client.buttons.get(interaction.customId) if (!button) return console.error(`No button id matching ${interaction.customId} was found.`) console.log(`Button '${interaction.customId}' clicked by ${interaction.user.tag}`) if (playerButtons.includes(interaction.customId)) { await playerEdit(interaction) } try { await button.execute(interaction) } catch (error) { console.error(`Error clicking ${interaction.customId}:`, error) } } } }