deferUpdate while waiting for api response

After the initial CommandInteraction, I .deferReply while I wait for an api response, then I .editReply once it's complete. I then have a ButtonBuilder attached that allows the data to refresh. So I .deferUpdate while the data is refreshing, then I .update once complete. My issue is that it fails on the .deferUpdate as .deferReply has already been called. Is there a way to resolve this? (The API is external and sometimes takes more than 3 seconds to resolve, so the interaction times out if the .deferUpdate is not called)
2 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
nullopt
nulloptOP2y ago
// CommandInteraction.ts

await interaction.deferReply();
// fetch data from api - can take more than 3 seconds
await interaction.editReply({...});



// ButtonInteraction.ts

const handleUpdate = async (buttonInteraction: ButtonInteraction) => {
await buttonInteraction.deferUpdate() // fails
// re-fetch api data
await buttonInteraction.update({...}); // fails without .deferUpdate() due to api taking > 3 seconds to resolve
}
// CommandInteraction.ts

await interaction.deferReply();
// fetch data from api - can take more than 3 seconds
await interaction.editReply({...});



// ButtonInteraction.ts

const handleUpdate = async (buttonInteraction: ButtonInteraction) => {
await buttonInteraction.deferUpdate() // fails
// re-fetch api data
await buttonInteraction.update({...}); // fails without .deferUpdate() due to api taking > 3 seconds to resolve
}
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.
Ok, so I believe I have fixed it by:
// CommandInteraction.ts

await interaction.deferReply();
// fetch data from api - can take more than 3 seconds
await interaction.editReply({...});



// ButtonInteraction.ts

const handleUpdate = async (buttonInteraction: ButtonInteraction) => {
await buttonInteraction.deferUpdate()
// re-fetch api data
await buttonInteraction.editReply({...}); // <--- Changed this to .editReply
}
// CommandInteraction.ts

await interaction.deferReply();
// fetch data from api - can take more than 3 seconds
await interaction.editReply({...});



// ButtonInteraction.ts

const handleUpdate = async (buttonInteraction: ButtonInteraction) => {
await buttonInteraction.deferUpdate()
// re-fetch api data
await buttonInteraction.editReply({...}); // <--- Changed this to .editReply
}
Some one correct me if this is the wrong approach
Want results from more Discord servers?
Add your server