javascriptnode.jsdiscorddiscord.js

How to update existing message and then reply without InteractionAlreadyReplied error, discord js


I have an embed that needs to be updated and then a reply should trigger afterwards. The code takes about 5 seconds to complete so to prevent UnknownInteraction error, I added deferReply(). However, I can't get it to work.

Here's the exact flow:

  1. Click button on an embed message from bot
  2. The Embed should update
  3. A new message shows confirming the click

I used update on #2 step, and editReply or followUp on #3 but to no avail.

I'm receiving Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred. error on these 2 attempts:

Attempt 1

await interaction.deferReply();
await wait(5_000);
embed1 = embed1content;
embed2 = embed2content;
await interaction.update({ embeds: [embed1] });
interaction.followUp({ embeds: [embed2] });

Attempt 2

await interaction.deferReply();
await wait(5_000);
embed1 = embed1content;
embed2 = embed2content;
await interaction.update({ embeds: [embed1] });
interaction.editReply({ embeds: [embed2] });

Solution

  • This is what I did to resolve this.

    await interaction.deferReply();
    await wait(5_000);
    embed1 = embed1content;
    embed2 = embed2content;
    await interaction.message.edit({ embeds: [embed1] });
    interaction.editReply({ embeds: [embed2] });