I can send a png from a javascript buffer as a message attachment, but I cannot embed it.
My code looks like this:
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
- 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[email protected] and node 20.1.0
i dont think you can visualize SVG files in discord
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
have you tried building this attachment using AttachmentBuilder?
No, is the an example of how I can do that and make it display the attachment?
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 attachmentHOT DOG it just worked and I as dumb and did not set the right extension
Thanks @ShompiFlen