Attaching PNG buffers directly to embed.

I've been working with getting a verification system setup, Playing around with canvas and other libraries. I'm at the point where I have a return from another handler returning (text=the captcha code; imageBuffer=the PNG buffer.) I assumed I could just create an attachment directly from the buffer but I appear to have been wrong as in the embed sent, no image, nilch...
const attachment = new AttachmentBuilder(imageBuffer, { name: 'captcha.png' });
const attachment = new AttachmentBuilder(imageBuffer, { name: 'captcha.png' });
-# See attached file for reference to command handler function file with the code referred to in my query.
35 Replies
d.js toolkit
d.js toolkit2w 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
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
I will add that the handler that processes the embed messages isn't the issue here, I just went to test that and it handles fine. It's specifically this command file where I'm passing the buffer 💜
No description
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
Oh and another one, Why does d.js have a defer interaction endpoint. What is the use case of that, why would you ever want to defer an interaction?
treble/luna
treble/luna2w ago
because discord has that endpoint. It is for when you cant respond within 3 seconds
d.js docs
d.js docs2w ago
To share long code snippets, use a service like gist, sourcebin, pastebin, or similar instead of posting them as large code blocks or files.
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
Ahh I see I see
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
Pastebin
const globalClient = require('../../client.js');const { AttachmentB...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
Anyway! If you do want to lend a hand I'd love to borrow your brain on the captcha issue <3
zevnda
zevnda2w ago
Can we see the generate function?
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
Ah yeah sure, let me pop it on a pastebin! ^^
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
Pastebin
const globalClient = require('../../../client.js');const svgCaptcha...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
zevnda
zevnda2w ago
In your generate function have you tried logging captcha and svguffer to make sure they're correct?
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
Yeah, They're all as expected, None are null I should have mentioned it but passing it directly as a attatchment not in an embed, it works fine I'll go double check again though, It was a few hours ago that I tested that
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
No description
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
Sorry just wanted to be sure Yeah, it's only in an embed for some reason
zevnda
zevnda2w ago
Hmm, I doubt it'll be the issue as I think they're processed at the same time anyway, but can you try putting files before embeds? Also try logging Buffer.isBuffer(attachment) .. though the buffer is clearly valid
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
I'll go give it a go!
zevnda
zevnda2w ago
If that doesn't work, can we see globalClient.embedHandler.send()
Retro
Retro2w ago
i think that will always return false? (correct me if im wrong) because attachment is a typeof AttachmentBuilder. i think what you were looking for is attachment.attachment
zevnda
zevnda2w ago
Right sorry, I meant on the actual buffer returned from the generate function
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
but can you try putting files before embeds?
Just ran that test, Same outcome. Content of buffer: <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 01 2c 00 00 00 96 08 06 00 00 00 64 5b b5 d2 00 00 00 09 70 48 59 73 00 00 0b 13 00 00 0b 13 01 ... 24822 more bytes> It just contains the binary of the converted png well... converted svg (to png)
zevnda
zevnda2w ago
Alright, let's see this
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
Pastebin
// src/modules/functions/handlers/embedHandler.jsconst { EmbedBuild...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
What confuses me is that, when using the handler for.. well images by URI wait.. it's just clicked am i not handling attatchments god damn it i don't think i am :TheVoices: IM NOT LMAO?! I am confusing myself now pff
zevnda
zevnda2w ago
Your messageOptions isn't handling files
Retro
Retro2w ago
yeah
No description
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
Yep... welp, thank you two for dealing with my idiocy 💜 I have moments like this lmao well, easy fix! im happy
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
No description
zevnda
zevnda2w ago
It happens. I am curious though, why such a roundabout way of handling message options like that anyway?
zevnda
zevnda2w ago
Nice!
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
I get that a lot actually, I have minor OCD, I really don't like writing the same code again and again and again. So I send to modularise my code into handlers It also helps me keep the program organised and scalable It takes more effort to do, but I find it's just a teeny bit more easy for me to work with
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
No description
zevnda
zevnda2w ago
That's fair. If it works for you that's all that really matters. Was just curious 🙂 best of luck
Kiɾʌ Kenjiɾø
Kiɾʌ KenjiɾøOP2w ago
💜
Want results from more Discord servers?
Add your server