Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

517
Views
Downloading a message attachment in discord.js

I'm making a map loader that relies on attachments and .txt files. I could do it with normal text, but since Discord has a character limit for each message, it doesn't work.

That's why I want to download message attachments on my local machine to process them further.

How can I download attachments from Discord messages using fs?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think you can just use a simple get request to the image's url (you can get this through attachment.url) using node-fetch then pipe the response to a .png file using fs

(If you get errors while installing node-fetch or while using the code below, try installing node-fetch v2 instead of the latest release via npm install node-fetch@2)

const fs = require('fs')
const fetch = require('node-fetch')

const imageUrl = 'https://cdn.discordapp.com/attachments/GLD_ID/MSG_ID/IMAGE.png'

fetch(imageUrl)
    .then(res =>
        res.body.pipe(fs.createWriteStream('./path/to/image.png'))
    )

You can also read this post which goes into more detail

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!