Yet another Fluxer bot built with TypeScript and Bun
at develop 47 lines 1.2 kB view raw
1import { Client, Events, Message } from "@fluxerjs/core"; 2import { env } from "@/env"; 3import { CommandRegistry } from "@/registry/commandRegistry"; 4import { loadModules } from "@/registry/loadModules"; 5import { watchCommands } from "@/registry/watchCommands"; 6import { Logger } from "tslog"; 7 8const IS_DEV = process.env.NODE_ENV !== "production"; 9 10export class Bot { 11 private client: Client; 12 private registry: CommandRegistry; 13 private readonly logger: Logger<Bot>; 14 15 constructor() { 16 this.client = new Client({ intents: 0 }); 17 this.registry = new CommandRegistry(); 18 this.logger = new Logger({ 19 type: "pretty", 20 name: "Bot", 21 }); 22 } 23 24 registerEvents() { 25 this.client.on(Events.MessageCreate, async (msg: Message) => { 26 await this.registry.handle({ client: this.client }, env.PREFIX, msg); 27 }); 28 29 this.client.on(Events.Ready, () => { 30 this.logger.info("Sucessfully started the bot!"); 31 }); 32 } 33 34 async start() { 35 this.logger.info("Starting Hydro..."); 36 37 await loadModules(this.registry, env.PREFIX); 38 39 if (IS_DEV) { 40 watchCommands(this.registry, env.PREFIX); 41 } 42 43 this.registerEvents(); 44 45 await this.client.login(env.FLUXER_BOT_TOKEN); 46 } 47}