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

392
Visualizações
Comppresing folder to zip in node.js

I'm creating a discord bot in discord.js that saves messages on the server. I would like to make it send a .zip compressed file from the saved messages folder. I know how to send attechment but I don't know how to add files from directory to this zip

I tried this:

But files aren't appending in zip.
Could someone please send fixed code?
Thank you in advance for your help.

var fs = require("fs");
var JSZip = require("jszip");
var zip = new JSZip();

zip
   .folder("data");
   .generateNodeStream({ type: 'nodebuffer', streamFiles: true })

  .pipe(fs.createWriteStream("logs.zip"))
   .on('finish', function () {
       console.log("out.zip written.");
   });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

At the Discord.js Documentation in stable version, TextChannel reference has a method send that allow send remote and local files.

Sample code of documentation for send a local file:

// Send a local file
channel.send({
  files: [{
    attachment: 'entire/path/to/file.jpg',
    name: 'file.jpg'
    description: 'A description of the file'
  }]
})
  .then(console.log)
  .catch(console.log);

You can build a absolute path file with the path module and give as attachment value.

const path = require('path');
const ABSOLUTE_PATH_FILE = path.resolve(__dirname, "./../files/filename.zip");
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