Skip to content

Commit

Permalink
Better handle uploading emojis
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathund committed Sep 24, 2024
1 parent a337a48 commit 181a801
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions Setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/* eslint-disable require-await */
/* eslint-disable no-console */
import chalk from 'chalk';
import { Client, GatewayIntentBits, OAuth2Scopes, PermissionsBitField } from 'discord.js';
import {
ApplicationEmoji,
Client,
ClientApplication,
GatewayIntentBits,
OAuth2Scopes,
PermissionsBitField
} from 'discord.js';
import { confirm, input, number, password } from '@inquirer/prompts';
import { existsSync, readdirSync, unlinkSync, writeFileSync } from 'fs';
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

async function uploadEmojisToBot(token: string) {
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
Expand All @@ -13,17 +21,26 @@ async function uploadEmojisToBot(token: string) {
if (!application) return;
const currentEmojis = await application.emojis.fetch();
if (0 < currentEmojis.size) {
console.log('You already have emojis uploaded to the bot. Please remove them or upload these emojis manually.');
} else {
console.log(chalk.red(chalk.bold('Emojis already exist.')));
const check = await confirm({ message: 'Overrite Emojis?', default: true });
if (false === check) {
client.destroy();
return;
}
currentEmojis.forEach(async (emoji: ApplicationEmoji) => {
await emoji.delete().then((emoji: ApplicationEmoji) => console.log(`Deleted ${emoji.name} Emoji`));
});
}
delay(5000).then(async () => {
const emojiFiles = readdirSync('./emojis').filter((file) => file.endsWith('.png'));
for (const emoji of emojiFiles) {
application.emojis
.create({ attachment: `./emojis/${emoji}`, name: emoji.split('.')[0] })
.then((emoji) => console.log(`Uploaded ${emoji.name} emoji`))
.then((emoji: ApplicationEmoji) => console.log(`Uploaded ${emoji.name} Emoji`))
.catch(console.error);
}
}
client.destroy();
await client.destroy();
});
});
}

Expand All @@ -46,7 +63,7 @@ async function setupBot(token: string) {
console.log(
`If you want to make the bot user installable, enable it on the Developer Portal. Link: https://discord.com/developers/applications/${application.id}/installation`
);
client.destroy();
await client.destroy();
});
}

Expand Down

0 comments on commit 181a801

Please sign in to comment.