Search code examples
javascriptnode.jsdiscorddiscord.jsembed

How to update and reply at the same time for an interaction, discord.js?


I'm experiencing an interaction error interaction has already been acknowledged when attempting to update and reply. This is because I already replied to the interaction through update/reply once.

What I want to do is when a user clicks the button on an embed message, the embed message gets updated/edited and then a hidden/ephemeral message is also sent.

  1. Embed with button is shown.
  2. User clicks the button.
  3. Embed gets updated with new title.
  4. User gets a ephemeral reply saying "Success".

Here's the interaction code:

client.on("interactionCreate", async (interaction) => {
    if (interaction.customId === "button") {
        const embed = new EmbedBuilder()
        .setTitle("This is a new title")
         interaction.update({embeds: [embed]});
         await interaction.reply({content: "Succcess!", ephemeral: true});
    }
})

Solution

  • Use the ButtonInteraction#followUp() method instead. Note that the ButtonInteraction#update() must be awaited so it has time to internally set ButtonInteraction#replied to true. If not, you will get the InteractionNotReplied error.

    await interaction.update({ embeds: [embed] });
    await interaction.followUp({ content: "Succcess!", ephemeral: true });