1 file changed
+35
@@ -0,0 +1,35 @@
|
|||||||
|
import { assertRequiredEnv, env } from './config/env.js';
|
||||||
|
import { createClient } from './core/client.js';
|
||||||
|
import { loadCommands } from './core/command-loader.js';
|
||||||
|
import { registerEvents } from './core/event-loader.js';
|
||||||
|
import { logger } from './core/logger.js';
|
||||||
|
import { closeDatabase, initDatabase } from './database/index.js';
|
||||||
|
import { startWebhookServer } from './webhooks/server.js';
|
||||||
|
|
||||||
|
assertRequiredEnv(['DISCORD_TOKEN', 'DISCORD_CLIENT_ID', 'DISCORD_GUILD_ID']);
|
||||||
|
|
||||||
|
initDatabase();
|
||||||
|
|
||||||
|
const client = createClient();
|
||||||
|
|
||||||
|
for (const command of await loadCommands()) {
|
||||||
|
client.commands.set(command.data.name, command);
|
||||||
|
}
|
||||||
|
await registerEvents(client);
|
||||||
|
|
||||||
|
const webhookServer = env.webhook.enabled ? startWebhookServer(client) : null;
|
||||||
|
|
||||||
|
process.on('unhandledRejection', (reason) => logger.error('Unhandled promise rejection', reason));
|
||||||
|
process.on('uncaughtException', (error) => logger.error('Uncaught exception', error));
|
||||||
|
|
||||||
|
async function shutdown(signal) {
|
||||||
|
logger.info(`Received ${signal}, shutting down`);
|
||||||
|
webhookServer?.close();
|
||||||
|
await client.destroy();
|
||||||
|
closeDatabase();
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
process.once('SIGINT', shutdown);
|
||||||
|
process.once('SIGTERM', shutdown);
|
||||||
|
|
||||||
|
await client.login(env.discord.token);
|
||||||
Reference in new issue
Block a user