skip to Main Content

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] });

2

Answers


  1. Chosen as BEST ANSWER

    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] });
    

  2. The error tells you exactly the problem is.

    • If you already deferred the interaction, you can’t defer again, you have to use interaction.editReply() to reply to it.
    • If you already sent the reply with interaction.editReply(), you can’t use interaction.deferReply() again.

    Interactions are deferred so the command doesn’t timeout when the bot is executing it. If you don’t defer and the execution of the command takes more than 3 seconds (if I remember correctly), the command will timeout. So, you don’t need to use a wait funciton, deferring the interaction already waits.

    For the solution, you should store the first reply inside a variable, and update that reply after the button is clicked.

    await interaction.deferReply();
    // Do what you need to do here
    let reply = await interaction.editReply({...});
    
    // Inside your collector
    await collectorInteraction.deferUpdate();
    await reply.edit({ embeds: [embed1] });
    await reply.followUp({ embeds: [embed2] });
    

    Note: deferUpdate() is used to acknowledge the button press interaction.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search