Attachment in embed

Hey, how can I turn interaction.options.getAttachment("image"); into an attachment to use in an embed? I've tried to do const attachment = new AttachmentBuilder(interaction.options.getAttachment("image"), "image.png"); but it says "The resource must be a string, Buffer or a valid file stream." and I can't figure out how to turn it into a buffer. Could anyone help?
6 Replies
d.js toolkit
d.js toolkit14mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Goose
Goose14mo ago
const user = await interaction.guild.members.fetch(interaction.user.id);
const title = interaction.options.getString("title") || "New Update";
console.log(Buffer.from(interaction.options.getAttachment("image")));
const attachment = new AttachmentBuilder(Buffer.from(interaction.options.getAttachment("image")), "image.png");


const embed = new EmbedBuilder()
.setColor(0xbd0d0d)
.setTitle(title)
.setDescription("hi")
.setThumbnail("attachment://image.png")
.setTimestamp()
.setFooter({ text: `Sent by ${user.username}`, iconURL: "redacted" });

await interaction.reply({ embeds: [embed], files: [{attachment: attachment}] });
const user = await interaction.guild.members.fetch(interaction.user.id);
const title = interaction.options.getString("title") || "New Update";
console.log(Buffer.from(interaction.options.getAttachment("image")));
const attachment = new AttachmentBuilder(Buffer.from(interaction.options.getAttachment("image")), "image.png");


const embed = new EmbedBuilder()
.setColor(0xbd0d0d)
.setTitle(title)
.setDescription("hi")
.setThumbnail("attachment://image.png")
.setTimestamp()
.setFooter({ text: `Sent by ${user.username}`, iconURL: "redacted" });

await interaction.reply({ embeds: [embed], files: [{attachment: attachment}] });
d.js docs
d.js docs14mo ago
Documentation suggestion for @goosetheboy:class AttachmentBuilder Represents an attachment builder
probablyraging
probablyraging14mo ago
Use the url property of the Attachment returned by getAttachment()
d.js docs
d.js docs14mo ago
Goose
Goose14mo ago
Didn't realize I could just use the URL. Thank you