//collector event (collect) collector.on("collect", async (c) => { //option const option = c.customId; //save if (option === "save") { //modal const modal = new ModalBuilder() .setCustomId("embedName") .setTitle("Embed name"); //create the text input components const embedNameInput = new TextInputBuilder() .setCustomId("embedName") .setLabel("Enter the name of the embed") .setStyle(TextInputStyle.Short); //embed name input const firstActionRow = new ActionRowBuilder().addComponents(embedNameInput); //add inputs to the modal modal.addComponents(firstActionRow); //show the modal to the user await c.showModal(modal); //disable all components save.components.forEach((component) => component.setDisabled(true)); //update the buttons await i.editReply({ components: [save] }); }; }); //create the modal collector const modalCollector = i.awaitModalSubmit({ time: 60000 }).catch(); //modal const modal = await modalCollector; //get the embed name const embedName = modal.fields.getTextInputValue("embedName"); //defer the modal modal.deferReply({ ephemeral: true }); //get the embeds data Embed.findOne({ guildId: i.guild.id, }, async (err, data) => { if (err) throw err; if (data) { console.log(`if statement ran!`); //embed name let name = embedName; //find the embed const obj = data.embeds.find(embed => embed.name === name); //if an embed with a similar name exists if (obj) name += 1; //save the embed Embed.findOneAndUpdate({ guildId: i.guild.id }, { $push: { embeds: { name: name, data: checkData.resolvedData } } }, async (err, data) => { if (err) throw err; }); //send the success message modal.reply({ embeds: [ new EmbedBuilder() .setColor(config.mainColor) .setDescription(`Embed saved successfully!`) ], ephemeral: true }); } else { console.log(`else statement ran!`); //create and save the data const doc = new Embed({ guildId: i.guild.id, embeds: [{ name: embedName, data: checkData.resolvedData }] }); await doc.save(); //send the success message modal.followUp({ embeds: [ new EmbedBuilder() .setColor(config.mainColor) .setDescription(`Embed saved successfully!`) ], ephemeral: true }); } });