-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
70 lines (56 loc) · 2.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(async()=>{
"use strict";
// Dependencies
const fileDownloader = require("nodejs-file-downloader")
const axios = require("axios")
const fs = require("fs")
// Variables
const args = process.argv.slice(2)
// Main
if(!args.length) return console.log("node index.js <token> <guildId> <outputDirectory>")
if(!args[1]) return console.log("Invalid guildId.")
if(!args[2]) return console.log("Invalid outputDirectory.")
if(!fs.existsSync(args[2])) return console.log("Invalid outputDirectory.")
const guildEmojis = await axios({
method: "GET",
url: `https://discord.com/api/v6/guilds/${args[1]}/emojis`,
headers: {
authorization: args[0]
}
}).catch(()=>{
console.log("Invalid guildID/discord_token.")
process.exit()
})
const guild = await axios({
method: "GET",
url: `https://discord.com/api/v6/guilds/${args[1]}`,
headers: {
authorization: args[0]
}
})
const emojis = guildEmojis.data
if(emojis.length){
console.log(`${emojis.length} emojis found in ${guild.data.name}.`)
console.log(`Downloading has started.`)
var emojiIndex = 0
async function download(){
if(emojiIndex === emojis.length) return console.log("Downloading is finished.")
const downloadFile = new fileDownloader({
url: `https://cdn.discordapp.com/emojis/${emojis[emojiIndex].id}.${ emojis[emojiIndex].animated ? "gif" : "png" }`,
directory: args[2],
fileName: `${emojis[emojiIndex].name}.${ emojis[emojiIndex].animated ? "gif" : "png" }`
})
try{
await downloadFile.download()
console.log(`Status: Success | Emoji link: https://cdn.discordapp.com/emojis/${emojis[emojiIndex].id}.${ emojis[emojiIndex].animated ? "gif" : "png" }`)
}catch{
console.log(`Status: Failed | Emoji link: https://cdn.discordapp.com/emojis/${emojis[emojiIndex].id}.${ emojis[emojiIndex].animated ? "gif" : "png" }`)
}
emojiIndex++
download()
}
download()
}else{
console.log(`No emojis found in ${guild.data.name}.`)
}
})()