Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

519
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda