image in embed

I'm working on something and I'm genuinely confused why this doesn't work. I've looked at previous questions about it but none of it works for me. I've tried both with EmbedBuilder and embed object, but both dont work
const image = await generateRankCard(playerData);
console.log(image);

const embed = new EmbedBuilder()
.setTitle(`${interaction.user.username}'s rank`)
.setImage(`attachment://${image.url}`);

const embedObject = {
title: `${interaction.user.username}'s rank`,
image: {
url: `attachment://${image.url}`,
},
};
return interaction.editReply({ embeds: [embedObject] }); // files: [image]
const image = await generateRankCard(playerData);
console.log(image);

const embed = new EmbedBuilder()
.setTitle(`${interaction.user.username}'s rank`)
.setImage(`attachment://${image.url}`);

const embedObject = {
title: `${interaction.user.username}'s rank`,
image: {
url: `attachment://${image.url}`,
},
};
return interaction.editReply({ embeds: [embedObject] }); // files: [image]
the image is made with the AttachmentBuilder and canvas:
const attachment = new AttachmentBuilder(canvas.toBuffer("image/png"), {
name: "rank-card.png",
});
const attachment = new AttachmentBuilder(canvas.toBuffer("image/png"), {
name: "rank-card.png",
});
as you can probably tell, I've tried sending the image as file, and that does work and show the image. this is what the console.log(image) shows;
AttachmentBuilder {
attachment: <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 03 20 00 00 01 c2 08 06 00 00 00 17 63 ad c8 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 00 04 ... 40080 more bytes>,
name: 'rank-card.png',
description: undefined
}
AttachmentBuilder {
attachment: <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 03 20 00 00 01 c2 08 06 00 00 00 17 63 ad c8 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 00 04 ... 40080 more bytes>,
name: 'rank-card.png',
description: undefined
}
could anyone possibly help me?
5 Replies
d.js toolkit
d.js toolkit4w 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
Retro
Retro4w ago
could you log image.url? if image is an instance of attachment builder, url doesnt exists because for a url to exists, it must be sent first the attchment:// protocol takes a file name, not a url be sure to include your last comment too // files: [image] becuase thats the piece of code that actually uploads the file to discord
ehz
ehzOP4w ago
you're right, image does not have an image.url, I've tried with image.name (and logged it), but this doesn't work either. the log gives rank-card.png isn't that to send it as file attachment and not as embed image tho?
Retro
Retro4w ago
you still need to send the file regardless of if you want to display it inside attachment or not. the attachment:// protocol will make it inside the embed https://discordjs.guide/popular-topics/embeds.html#attaching-images
ehz
ehzOP4w ago
I totally overlooked that in the guide, my fault. this works thanks!

Did you find this page helpful?