Kord/src/client/KordClient.ts

48 lines
1.4 KiB
TypeScript

import { Client, GatewayIntentBits, Partials, Collection } from 'discord.js';
import { logger } from '../utils/logger';
import { env } from '../config/env';
import { loadCommands } from '../handlers/CommandLoader';
import { loadEvents } from '../handlers/EventLoader';
import { handleGlobalExceptions } from '../utils/errorHandler';
import { connectDB } from '../database';
import { connectRedis } from '../cache';
export class KordClient extends Client {
public commands: Collection<string, any> = new Collection();
constructor() {
super({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages,
// GatewayIntentBits.MessageContent, // Privileged -> Disabled for testing
// GatewayIntentBits.GuildMembers, // Privileged -> Disabled for testing
GatewayIntentBits.GuildInvites,
],
partials: [Partials.Message, Partials.Channel, Partials.GuildMember],
});
}
public async start() {
handleGlobalExceptions();
// Connect to external services
await connectDB();
await connectRedis();
// Load Handlers
await loadCommands(this);
await loadEvents(this);
if (!env.DISCORD_TOKEN) {
logger.warn('DISCORD_TOKEN is missing. Bot cannot start.');
return;
}
// Login
await this.login(env.DISCORD_TOKEN);
logger.info(`Started login sequence...`);
}
}