Understanding the differences between various deleteReply functions

Discordjs version: [email protected] Node version: v20.8.1 I've got a SlashCommand that spawns the interaction shown in the picuture. The idea is to show a ephemeral message, click a button to "edit" various options and then after pressing "apply" show the new overview of the settings. I'm struggling to understand the differences between the various "deleteReply" functions. I have this function button_updateSettings to handle the click event for the "Apply" button.
async function button_updateSettings(interaction: ButtonInteraction) {
const loadingMessage = await interaction.deferReply({ ephemeral: true })

await new Promise((resolve, _reject) => setTimeout(() => resolve(undefined), 5000))

// works! Deletes the deferReply() loading message
// await interaction.deleteReply()

// does not work! throws "DiscordAPIError[10008]: Unknown Message"
// await interaction.deleteReply(loadingMessage.id)

// works, but deletes the original interaction message and not the deferReply() loading message
// await interaction.deleteReply(interaction.message.id)

// does not work! throws "DiscordAPIError[10008]: Unknown Message"
// await interaction.webhook.deleteMessage(loadingMessage.id)


// update original message
// works fine
await interaction.editReply({
message: interaction.message.id,
content: "Edited",
embeds: [],
components: [],
})
}
async function button_updateSettings(interaction: ButtonInteraction) {
const loadingMessage = await interaction.deferReply({ ephemeral: true })

await new Promise((resolve, _reject) => setTimeout(() => resolve(undefined), 5000))

// works! Deletes the deferReply() loading message
// await interaction.deleteReply()

// does not work! throws "DiscordAPIError[10008]: Unknown Message"
// await interaction.deleteReply(loadingMessage.id)

// works, but deletes the original interaction message and not the deferReply() loading message
// await interaction.deleteReply(interaction.message.id)

// does not work! throws "DiscordAPIError[10008]: Unknown Message"
// await interaction.webhook.deleteMessage(loadingMessage.id)


// update original message
// works fine
await interaction.editReply({
message: interaction.message.id,
content: "Edited",
embeds: [],
components: [],
})
}
What is the correct/best way to delete the "Bot is waiting..." message? Why do some options not work/throw an error?
No description
3 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
duck
duck14mo ago
<Interaction>.deleteReply() deletes a reply to an interaction by default it deletes the initial response, but you can delete a different message by specifying a message id this is why await interaction.deleteReply(interaction.message.id) deletes the message the component is on, because that's the message you told it to delete <Interaction>.deleteReply() internally just uses <Interaction>.webhook.deleteMessage(), so you're free to use either method the issue with using loadingMessage.id in your second and fourth examples is that deferReply resolves in an InterationResponse if you don't specify fetchReply: true in the options in this case, loadingMessage.id would be the button interaction's id, which isn't a valid message id all of this being said, is there a reason you're not just using <ButtonInteraction>.update() or <ButtonInteraction>.deferUpdate()?
Linus
LinusOP14mo ago
thank you for the detailed response! This example was mostly for demonstration purposes because I was confused as to why the second and fourth example would differ from the third, I wasn't aware of the fetchReply: true option. Regarding update()/deferUpdate(), maybe I misunderstood the docs but isn't editReply supposed to be an alternative? Why would I still need to call update()/deferUpdate()? (I'm currently busy but I will try it later this day)
Want results from more Discord servers?
Add your server