-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathupload-emojis.js
executable file
·69 lines (52 loc) · 1.95 KB
/
upload-emojis.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
const Discord = require('discord.js');
const fs = require('fs').promises;
const path = require('path');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const helper = require('./helper.js');
const client = new Discord.Client({autoReconnect:true});
client.on('error', console.error);
const config = require('./config.json');
let guilds = [];
client.on('ready', () => {
client.guilds.cache.array().forEach(guild => {
if(guild.me.hasPermission('MANAGE_EMOJIS'))
guilds.push(guild);
});
if(guilds.length == 0)
throw "Bot has no servers to upload emotes to";
guilds.forEach((guild, index) => {
let staticEmojis = guild.emojis.cache.filter(a => !a.animated && !a.deleted && !a.managed).array().length;
console.log(index, `${guild.name} - ${staticEmojis} / 50 or more emote slots`);
});
rl.question('Server to upload the emotes to (server index): ', answer => {
let index = Number(answer);
if(isNaN(index))
throw "Input is not a number";
if(index < 0 || index >= guilds.length)
throw "Invalid range, please choose a valid server index";
let guild = guilds[index];
fs.readdir('./emotes').then(files => {
let promises = [];
files.forEach(file => {
if(path.extname(file) == '.png')
promises.push(
guild.emojis.create(`./emotes/${file}`, path.basename(file, path.extname(file)))
);
});
Promise.all(promises).then(() => {
console.log(`${promises.length} emotes successfully uploaded!`);
rl.close();
process.exit(0);
}).catch(err => {
throw err;
});
}).catch(err => {
throw err;
});
});
});
client.login(config.credentials.bot_token);