Deleting ephemeral replies

Is there a way to delete/hide a previous ephemeral reply after user clicks the button? I know await interaction.deleteReply(); will do it, but im not sure how to point it correctly here so its targeting the previous reply instead of the current one. My thinking is ill need to write a function to do so? fetch interaction.id -> forward it, then delete that id after the new reply is created
const {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
} = require("discord.js");

module.exports = {
data: {
name: `confirmation-menu`,
},
async execute(interaction) {

const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Confirm')
.setStyle(ButtonStyle.Success);

const cancel = new ButtonBuilder()
.setCustomId('cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Danger);

await interaction.reply({
components: [new ActionRowBuilder().addComponents(confirm, cancel)],
ephemeral: true,
});
},
};
const {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
} = require("discord.js");

module.exports = {
data: {
name: `confirmation-menu`,
},
async execute(interaction) {

const confirm = new ButtonBuilder()
.setCustomId('confirm')
.setLabel('Confirm')
.setStyle(ButtonStyle.Success);

const cancel = new ButtonBuilder()
.setCustomId('cancel')
.setLabel('Cancel')
.setStyle(ButtonStyle.Danger);

await interaction.reply({
components: [new ActionRowBuilder().addComponents(confirm, cancel)],
ephemeral: true,
});
},
};
module.exports = {
data: {
name: `confirm`,
},
async execute(interaction) {
await interaction.reply({
content: `Confirmed`,
});
},
};
module.exports = {
data: {
name: `confirm`,
},
async execute(interaction) {
await interaction.reply({
content: `Confirmed`,
});
},
};
4 Replies
d.js toolkit
d.js toolkit10mo 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
d.js docs
d.js docs10mo ago
:method: ChatInputCommandInteraction#deleteReply() Deletes a reply to this interaction. :method: InteractionWebhook#deleteMessage() Delete a message that was sent by this webhook.
monbrey
monbrey10mo ago
Both can be passed a reference to the message to delete
Nilin
NilinOP10mo ago
ohhhhh perfect thank you guys so much
Want results from more Discord servers?
Add your server