import { Client, GatewayIntentBits, Events, ActivityType, REST } from "discord.js"; import Commands from "./Commands/Commands"; import {Container} from "../Container/Container"; import {Logger} from "log4js"; import {InteractionRouter} from "./InteractionRouter"; export class DiscordClient { private readonly client: Client; public get Client(): Client { return this.client; } public get Commands(): Commands { return this.router.commands } public get RESTClient(): REST { return this.restClient; } public get ApplicationId(): string { return this.applicationId; } constructor( private readonly applicationId: string, private readonly router: InteractionRouter, private readonly restClient: REST = new REST() ) { this.client = new Client({ intents: [GatewayIntentBits.Guilds] }) } applyEvents() { this.client.once(Events.ClientReady, () => { if (!this.client.user) { return; } Container.get("logger").info(`Ready! Logged in as ${this.client.user.tag}`); this.client.user.setActivity('your PnP playdates', { type: ActivityType.Watching, }); }) this.client.on(Events.GuildAvailable, () => { Container.get("logger").info("Joined Guild?") }) this.client.on(Events.InteractionCreate, this.router.route.bind(this.router)); } connect(token: string) { this.client.login(token); } connectRESTClient(token: string) { this.restClient.setToken(token); } }