vedel
vedel
DIAdiscord.js - Imagine an app
Created by vedel on 1/23/2024 in #djs-questions
How to edit the inital reply after ModalSubmitInteraction?
I am using Node v20.11.0 and discord.js v14.14.1. Initial reply:
const button = new ButtonBuilder()
.setCustomId('submit-modal')
.setLabel('Click me')
.setStyle(ButtonStyle.Primary);

const row = new ActionRowBuilder<ButtonBuilder>().addComponents(button);

return interaction.reply({ embeds: [embed], components: [row] });
const button = new ButtonBuilder()
.setCustomId('submit-modal')
.setLabel('Click me')
.setStyle(ButtonStyle.Primary);

const row = new ActionRowBuilder<ButtonBuilder>().addComponents(button);

return interaction.reply({ embeds: [embed], components: [row] });
Modal (after button is clicked)
const modal = new ModalBuilder()
.setCustomId('submit-modal')
.setTitle('Welcome!');

const textinput = new TextInputBuilder()
.setCustomId('name')
.setLabel('What is your name?')
.setRequired(true)
.setStyle(TextInputStyle.Short);

const row = new ActionRowBuilder<TextInputBuilder>().addComponents(textinput);

modal.addComponents(row);

await interaction.showModal(modal);
const modal = new ModalBuilder()
.setCustomId('submit-modal')
.setTitle('Welcome!');

const textinput = new TextInputBuilder()
.setCustomId('name')
.setLabel('What is your name?')
.setRequired(true)
.setStyle(TextInputStyle.Short);

const row = new ActionRowBuilder<TextInputBuilder>().addComponents(textinput);

modal.addComponents(row);

await interaction.showModal(modal);
After Submit:
const embed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('Welcome!')
.setDescription(`Hi ${name}`);

//How do I update the first message?
//I want to replace the initial reply with the new embed
const embed = new EmbedBuilder()
.setColor(0x00ff00)
.setTitle('Welcome!')
.setDescription(`Hi ${name}`);

//How do I update the first message?
//I want to replace the initial reply with the new embed
I tried:
console.log(interaction.message) //Exists
interaction.message.edit({ embeds [embed] });
console.log(interaction.message) //Exists
interaction.message.edit({ embeds [embed] });
-> Could not find the channel where this message came from in the cache!
console.log(interaction.message) //Exists
interaction.editReply({ embeds: [embed] });
console.log(interaction.message) //Exists
interaction.editReply({ embeds: [embed] });
-> The reply to this interaction has not been sent or deferred. The goal is to prevent the user from clicking again on the modal button and display a welcome message.
8 replies