-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiconsUpload.ts
48 lines (42 loc) · 1.29 KB
/
iconsUpload.ts
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
import { Client } from 'discordx';
import { secrets } from '../src/config';
import fs from 'fs/promises';
const client = new Client({
intents: [
'Guilds',
'GuildMessages',
'DirectMessages',
'MessageContent',
],
silent: false,
});
const token = secrets.token;
if (!token) {
throw new Error('No token provided');
}
await client.login(token);
const icons = await fs.readdir('icons');
const images = await Promise.all(icons.map(icon => fs.readFile(`icons/${icon}`)));
let i = 0;
for (const image of images) {
const name = icons[images.indexOf(image)].split('.')[0];
const exists = client.application?.emojis.cache.find(emoji => emoji.name === name);
if (exists) {
console.log(`Skipping ${exists.name} because it already exists, ${++i}/${images.length} emojis`);
continue;
}
try {
await client.application?.emojis.create({
name,
attachment: image
})
console.log(`Uploaded ${++i}/${images.length} emojis`);
} catch (error: any) {
console.log(`Failed to upload ${name}, ${++i}/${images.length} emojis`);
if (error.toString().includes('exceeds')) {
console.error(error)
console.log(`${name} exceeds the limit`);
}
continue;
}
}