import { Client, Collection, GatewayIntentBits, Partials, ShardingManager } from "discord.js"; import IBot from "../interfaces/IBot"; import IConfig from "../interfaces/IConfig"; import Handler from "./Handler"; import Interaction from "./Interaction"; import SubCommand from "./SubCommand"; import { connect } from "mongoose"; import { Util } from "../utils/Util"; export default class Bot extends Client implements IBot { public readonly handler: Handler public readonly config: IConfig; public readonly commands: Collection; public readonly subCommands: Collection; public readonly cooldowns: Collection>; public readonly interactions: Collection = new Collection(); public readonly util!: Util; constructor() { super({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildExpressions, GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildIntegrations, GatewayIntentBits.GuildModeration, GatewayIntentBits.MessageContent ], partials: [ Partials.GuildMember, Partials.User, Partials.Reaction, Partials.Channel, Partials.Message, ], }) this.config = require(`${process.cwd()}/data/config.json`); this.handler = new Handler(this); this.commands = new Collection(); this.subCommands = new Collection(); this.cooldowns = new Collection(); this.util = new Util(this); } Init(): void { console.log(`✅ Starting the bot in production mode.`); this.LoadHandlers(); const manager = new ShardingManager('./src/index.ts', { token: '' }); manager.on('shardCreate', (shard) => console.log(`Started shard ${shard.id}`)); manager.spawn() this.login(this.config.token) .catch((err) => console.error(err)); connect(this.config.mongoUrl) .then(() => console.log(`✅ Connected to MongoDB`)) .catch((err) => console.log(err)); } LoadHandlers(): void { this.handler.LoadEvents(); this.handler.LoadCommands(); } }