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.");
});
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");