How to make an attachment from an http response

I'm making an http request with await fetch(imageUrl) and would like to turn that into an Attachment for use in an embed thumbnail. What is the most efficient way to do that? I'm kinda struggling with streams and buffers.
6 Replies
d.js toolkit
d.js toolkit2mo 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
DaniDipp
DaniDipp2mo ago
discord.js@14.14.1 node v20.11.1
monbrey
monbrey2mo ago
Dont even need to fetch it The AttachmentBuilder accepts URLs
DaniDipp
DaniDipp2mo ago
I can't just put the image url into the embed because the service blocks the discord crawler. I need my bot to download and rebupload it oh
monbrey
monbrey2mo ago
oh Hmm, might still work via attachment though
DaniDipp
DaniDipp2mo ago
I didn't notice that strings are BufferResolvables, I'll try that Works like a charm, thank you! :robClap: