I can send a png from a javascript buffer as a message attachment, but I cannot embed it.

My code looks like this:
makeMemeAsync('geordieDrake', before, after).then(buffer => {
initialQuery.channel.send({
content: 'Your meme sir',
files: [
{
attachment: buffer, name: 'geordieDrake.svg'
}
]
});
});
makeMemeAsync('geordieDrake', before, after).then(buffer => {
initialQuery.channel.send({
content: 'Your meme sir',
files: [
{
attachment: buffer, name: 'geordieDrake.svg'
}
]
});
});
makeMemeAsync() returns Promise<Buffer> a node buffer. This code works. It create a message with an attachment. I download the attachment and it is a png. I want to make the image displayed in the message instead of having to be downloaded. I am a little confused on how to make that happen.
8 Replies
d.js toolkit
d.js toolkit8mo 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
zippy1981
zippy19818mo ago
discord.js@14.13.0 and node 20.1.0
ShompiFlen
ShompiFlen8mo ago
i dont think you can visualize SVG files in discord
zippy1981
zippy19818mo ago
OH. That was a mistake. It's a png. A png made from a svg, but makeMeme is calling svg2img. The file. Is a png. And I originally gave it no extension. Then I downloaded it locally and added the png extension and it opened in photo viewer
ShompiFlen
ShompiFlen8mo ago
have you tried building this attachment using AttachmentBuilder?
zippy1981
zippy19818mo ago
No, is the an example of how I can do that and make it display the attachment?
ShompiFlen
ShompiFlen8mo ago
yes so the attachment should just be able to be visualized if its a valida image file / recognized by discord as an image try building the attachment with the builder like this const attachment = new AttachmentBuilder(buffer, {name: image.png}) then pass it to the send call .send({files:[attachment]}) make sure the buffer is actually of a png file and that the extensions match with the name of the attachment
zippy1981
zippy19818mo ago
HOT DOG it just worked and I as dumb and did not set the right extension Thanks @ShompiFlen