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:
- Click button on an embed message from bot
- The Embed should update
- 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
This is what I did to resolve this.
The error tells you exactly the problem is.
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.
Note: deferUpdate() is used to acknowledge the button press interaction.