FemScoreboard/discord/sync.ts

34 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-10-07 22:46:02 -07:00
/**
* sync.ts
* Syncs message reactions in chat with the database.
* The bot will do the same thing automatically upon startup, but this is just in the form of a standalone script.
2023-10-07 22:46:02 -07:00
*/
import { Client, Events, GatewayIntentBits, IntentsBitField, Partials } from 'discord.js';
import { db, openDb, reactionEmojis, sync } from './util';
2023-10-07 22:46:02 -07:00
const client = new Client({
intents: [GatewayIntentBits.MessageContent, IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});
client.once(Events.ClientReady, async () => {
console.log('[bot] Ready.');
for (let i = 0; i < reactionEmojis.length; ++i)
console.log(`[bot] config: reaction_${i + 1} = ${reactionEmojis[i]}`);
});
async function startup() {
console.log("[db] Opening...");
await openDb();
console.log("[db] Migrating...");
await db.migrate();
console.log("[db] Ready.");
console.log("[bot] Logging in...");
await client.login(process.env.TOKEN);
await sync(client.guilds);
2023-10-07 22:46:02 -07:00
process.exit(0);
}
startup();