DeferReply problem

Hello I want my code to clean up components under message that button was clicked and then send new message. i got this effect by update first and then sending followup
await interaction.update({components: []})
await interaction.followup({content: 'This is a follow-up message.', components: [row]});
await interaction.update({components: []})
await interaction.followup({content: 'This is a follow-up message.', components: [row]});
This code works as intended but when i add deferReply this code end every time with error:
Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
Do you have idea how would i fix that?
10 Replies
treble/luna
treble/luna6mo ago
you have to use editReply when deferring
SzyMoon
SzyMoon6mo ago
Sure thing but when i do update first then editReply i got Code:
await interaction.deferReply();
await new Promise(resolve => setTimeout(resolve, 5000));

await interaction.update({components: []})
await interaction.editReply({content: 'This is a follow-up message.');
await interaction.deferReply();
await new Promise(resolve => setTimeout(resolve, 5000));

await interaction.update({components: []})
await interaction.editReply({content: 'This is a follow-up message.');
Error:
Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
at ButtonInteraction.update (D:\Lief\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:225:46)
at Object.execute (D:\Lief\handlers\button\test.js:16:27)
at async Client.<anonymous> (D:\Lief\index.js:209:9) {
code: 'InteractionAlreadyReplied'
Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
at ButtonInteraction.update (D:\Lief\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:225:46)
at Object.execute (D:\Lief\handlers\button\test.js:16:27)
at async Client.<anonymous> (D:\Lief\index.js:209:9) {
code: 'InteractionAlreadyReplied'
treble/luna
treble/luna6mo ago
replace update with editReply
SzyMoon
SzyMoon6mo ago
interaction update deletes components under clicked message in that case, i cant editReply that i think. Or am i wrong?
treble/luna
treble/luna6mo ago
Use deferUpdate then
SzyMoon
SzyMoon6mo ago
deferUpdate also throws error already replied
treble/luna
treble/luna6mo ago
but did you use editReply afterwards
SzyMoon
SzyMoon6mo ago
Yup i messed up order. It works like this
await interaction.deferReply();
await interaction.deferUpdate({components: []})
await interaction.editReply({content: 'This is a follow-up message.'});
await interaction.deferReply();
await interaction.deferUpdate({components: []})
await interaction.editReply({content: 'This is a follow-up message.'});
Thank you so much for help!
treble/luna
treble/luna6mo ago
that should error though you can either deferReply which will show a ...is thinking message or deferUpdate which just expects you to update the message later on with editReply
SzyMoon
SzyMoon6mo ago
You are right. ok i didnt reload my code it works like this.
await interaction.deferUpdate()
await interaction.editReply({components:[]});
await interaction.followUp({content:"test"})
await interaction.deferUpdate()
await interaction.editReply({components:[]});
await interaction.followUp({content:"test"})
It's a shame that bot doesnt show that works to update something Thank you once again!