const { InteractionType, ActionRowBuilder, ButtonBuilder, StringSelectMenuBuilder, ModalBuilder, TextInputBuilder, ButtonStyle, TextInputStyle, EmbedBuilder } = require("discord.js"); const { bold } = require('kleur') const statusmodalobj = new ModalBuilder() .setTitle('Digite os status de seu dino') .setCustomId('statusmodal') module.exports = { name: "interactionCreate", async execute(interaction, client) { if (interaction.isButton()) { const button = client.buttons.get(interaction.customId); if (!button) return; try { button.execute(interaction, client); console.log } catch (error) { console.log(bold().red("[BUTTON ERROR]") + error); } } else if (interaction.isChatInputCommand()) { const command = client.commands.get(interaction.commandName); if (!command) return; try { command.execute(interaction, client); } catch (error) { console.log(bold().red("[COMMAND ERROR]") + error); } } else if (interaction.isStringSelectMenu()) { if (interaction.customId == 'statusmenu') { let addmutation = new ActionRowBuilder; let removemutation = new ActionRowBuilder; function addButtonAndInput(component) { const inputObj = new ActionRowBuilder() .addComponents( new TextInputBuilder() .setCustomId(`${component}input`) .setLabel(`${component.charAt(0).toUpperCase() + component.slice(1)}:`) .setStyle(TextInputStyle.Short)) const addButtonObj = new ButtonBuilder() .setCustomId(`a${component}`) .setLabel(component.charAt(0).toUpperCase() + component.slice(1)) .setStyle(ButtonStyle.Success) .setEmoji('<:Mutagen:1068352191154376784>') const removeButtonObj = new ButtonBuilder() .setCustomId(`r${component}`) .setLabel(component.charAt(0).toUpperCase() + component.slice(1)) .setStyle(ButtonStyle.Danger) .setEmoji('<:Mutagel:1068352150201176144>') addmutation.addComponents(addButtonObj) removemutation.addComponents(removeButtonObj) statusmodalobj.addComponents(inputObj) } interaction.values.forEach(option => { addButtonAndInput(option) }); interaction.showModal(statusmodalobj) } const select = client.selectMenus.get(interaction.customId.split(" ")[0]); if (!select) return; try { select.execute(interaction, client); } catch (error) { console.log(bold().red("[SELECTMENU ERROR]") + error); } } else if (interaction.isModalSubmit()) { if (interaction.customId == 'statusmodal') { const row2 = new ActionRowBuilder() .addComponents( new ButtonBuilder() .setCustomId('cancell') .setLabel('Cancelar') .setStyle(ButtonStyle.Danger) .setEmoji('<:uncheck:1068375001889243208>'), new ButtonBuilder() .setCustomId('continue') .setLabel('Continuar') .setStyle(ButtonStyle.Success) .setEmoji('<:check:1068377137700143186>') ) const postEmbed = EmbedBuilder.from(interaction.message.embeds[0]) let customIds = [] let awnsersArray = [] const textinputnames = [] console.log(statusmodalobj.components) for (let i = 0; i < statusmodalobj.components.length; i++) { console.log(statusmodalobj.components[i].components[0].data) const customIdm = statusmodalobj.components[i].components[0].data.custom_id const textinputname = statusmodalobj.components[i].components[0].data.label customIds.push(customIdm) textinputnames.push(textinputname) const awnser = interaction.fields.getTextInputValue(customIdm) awnsersArray.push(awnser) console.log(customIdm) console.log(customIds) console.log(awnser) console.log(awnsersArray) postEmbed.addFields({ name: textinputname, value: awnser }) } const messageinitial = interaction.message interaction.deferUpdate(); messageinitial.edit({ embeds: [postEmbed], components: [row2] }) } const modal = client.modals.get(interaction.customId); if (!modal) return; try { modal.execute(interaction, client); } catch (error) { console.log(bold().red("[MODAL ERROR]") + error); } } else if (interaction.type == InteractionType.ApplicationCommandAutocomplete) { const { commands } = client; const { commandName } = interaction; const command = commands.get(commandName); if (!command) return; try { await command.autocomplete(interaction, client) } catch (error) { console.log(bold().red("[AUTOCOMPLETE ERROR]") + error); } } }, };