greg
greg
DIAdiscord.js - Imagine an app
Created by greg on 9/3/2024 in #djs-questions
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]
});
},

...
8 replies