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.
6 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
vedel
vedelOP11mo ago
This seams to work:
await interaction.deferUpdate({ fetchReply: true });
await interaction.editReply({ embeds: [embed], components: [] });
await interaction.deferUpdate({ fetchReply: true });
await interaction.editReply({ embeds: [embed], components: [] });
Please let me know if this is bad practise or not 🙂 In the typescript definition it appears not to exist. The closest (by name atleast) is deferedUpdate.
monbrey
monbrey11mo ago
In TypeScript you need to first typeguard it
monbrey
monbrey11mo ago
You cant update unless its from a button/select menu
vedel
vedelOP11mo ago
Unfortunately I wasn't able to figure it out. For now I will keep it the ugly way.
Want results from more Discord servers?
Add your server