Question regarding ephemeral replies after defer

Hey, I'm trying to make a simple command that let's me stretch an attachment image and reply with the stretched image, which works perfectly. But the issues are the ephemeral replies. I want the error replies to be ephemeral and the actual result reply to be a normal reply, non ephemeral. The error replies are not ephemeral even when setting ephemeral: true. How would I be able to achieve ephemeral replies for the errors only and keep the result non ephemeral? 🙏 [email protected]
...

async execute(interaction, client) {
interaction.deferReply();

const imageURL = interaction.options.getAttachment('image').proxyURL;
const multiplier = interaction.options.getNumber('multiplier');

if (!isPngOrJpg(imageURL)) {
return interaction.editReply({ // sends as non ephemeral
embeds: [easyEmbed("#ff0000", "Attachment is not a png/jpg image")],
ephemeral: true
});
}

const image = await loadImage(imageURL);
let canvas;

try {
canvas = createCanvas(image.width * multiplier, image.height)
} catch {
return interaction.editReply({ // sends as non ephemeral
embeds: [easyEmbed("#ff0000", "Image width is too long")],
ephemeral: true
})
}

const ctx = canvas.getContext('2d');

ctx.drawImage(image, 0, 0, image.width * multiplier, image.height);

const buffer = canvas.toBuffer();
const attachment = new AttachmentBuilder(buffer, {
name: 'mw-stretch.png'
});

interaction.editReply({ // result stays non ephemeral
files: [attachment]
});
},

...
...

async execute(interaction, client) {
interaction.deferReply();

const imageURL = interaction.options.getAttachment('image').proxyURL;
const multiplier = interaction.options.getNumber('multiplier');

if (!isPngOrJpg(imageURL)) {
return interaction.editReply({ // sends as non ephemeral
embeds: [easyEmbed("#ff0000", "Attachment is not a png/jpg image")],
ephemeral: true
});
}

const image = await loadImage(imageURL);
let canvas;

try {
canvas = createCanvas(image.width * multiplier, image.height)
} catch {
return interaction.editReply({ // sends as non ephemeral
embeds: [easyEmbed("#ff0000", "Image width is too long")],
ephemeral: true
})
}

const ctx = canvas.getContext('2d');

ctx.drawImage(image, 0, 0, image.width * multiplier, image.height);

const buffer = canvas.toBuffer();
const attachment = new AttachmentBuilder(buffer, {
name: 'mw-stretch.png'
});

interaction.editReply({ // result stays non ephemeral
files: [attachment]
});
},

...
5 Replies
d.js toolkit
d.js toolkit3mo 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
monbrey
monbrey3mo ago
You can't if you defer, as the ephemeral must be set at that time. It can't be edited. You'll need to send a separate reply for anything that needs to be different
greg
gregOP3mo ago
A separate reply? Do you mean by using interaction.followUp?
monbrey
monbrey3mo ago
After updating the defer somehow, yes Otherwise followup will try to edit it
greg
gregOP3mo ago
Oh yes, it worked. Thank you very much 🙏
Want results from more Discord servers?
Add your server