Created
September 9, 2022 17:08
-
-
Save Digital39999/4169b65f53df216502cd4b6ad17ffff5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const channel = require('./channel'); | |
const https = require('https'); | |
const fs = require('fs'); | |
/* | |
I am not responsible if you damage any account, this is for educational purposes only. | |
Steps: | |
- You will have to use https://github.com/Tyrrrz/DiscordChatExporter to get channels.json file | |
- Place it into same folder as this file and rename it to channel.json | |
- Install modules with npm i fs https --save | |
- Run the script with node index.js | |
*/ | |
console.clear(); | |
main().then((data) => console.log(`\x1b[37m`, `\n\nDownloaded ${data.yes} files, failed ${data.no} files, skipped ${data.already} files, there were ${data.total} files in total.`)); | |
async function main() { | |
if (!fs.existsSync('./channel.json')) return console.log(`File channel.json was not found.`); | |
if (!fs.existsSync('./files')) fs.mkdirSync('./files'); | |
let yes = 0, no = 0, total = 0, alr = 0, counter = 0; | |
for await (const message of channel?.messages) { | |
if (message?.attachments?.length > 0) { | |
for await (const attachment of message?.attachments) { | |
if (attachment?.url?.length > 0) { | |
let extension = attachment?.url?.split('.').pop(), erCheck = false; total++; | |
if (fs.existsSync(`./files/${attachment?.id}.${extension}`)) { | |
console.log(`\x1b[33m`, `File ${attachment?.id}.${extension} already exists.`); alr++; | |
} else { | |
let file = fs.createWriteStream(`./files/${attachment?.id}.${extension}`); | |
let request = await https.get(attachment?.url, (response) => { | |
response.pipe(file); | |
file.on('finish', () => { | |
file.close((aaa) => { if (aaa) erCheck = true; }); console.log(`\x1b[32m`, `Downloaded ${attachment?.id}.${extension}`); yes++; | |
}); | |
}).on('error', (err) => { | |
fs.unlink(`./files/${attachment?.id}.${extension}`, (aaa) => { if (aaa) erCheck = true; }); if (erCheck == true) console.log(`\x1b[31m`, `Error downloading ${attachment?.id}.${extension}`); no++; | |
}); | |
}; | |
}; | |
}; | |
}; | |
}; | |
return new Promise((resolve, reject) => { | |
let interval = setInterval(() => { | |
if (yes + no + alr == total) { | |
clearInterval(interval); | |
return resolve({ | |
already: alr, | |
total: total, | |
yes: yes, | |
no: no, | |
}); | |
}; | |
}, 1000); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment