DiscordSaaSBot / SaaSBot

🤖 Discord bot for the builders and entrepreneurs community.
Apache License 2.0
11 stars 3 forks source link

chore: merge template #1

Closed stifskere closed 7 months ago

stifskere commented 7 months ago

Template

This template has strict typing, the flow for making a command or an event is the following.

Events

Create a new file inside the events folder, or any folder inside, the file inclusion is recursive, and add the following:

You must export a class that extends EventHandler, otherwise it will be ignored, the eventType getter is the name of the event to handle and the invoke method (can be async) is the event handler, this will run when the event is fired.

You have access to the client from this.client and for any event parameters add them to the invoke function.

export default class extends EventHandler {
    get eventType(): keyof ClientEvents {
        return Events.ClientReady;
    }

    invoke(): void {
        console.log("Client Ready!");
    }
}

Commands

Create a new file inside the commands folder, again, it's recursive. Then include the following:

You must export a class that extends SlashCommand, otherwise it will be ignored, the build getter should return the SlashCommandBuilder instance for this command and the run method is the handler for this command.

You have access to this.context as the command context and this.client as the client that executed this command.

export default class extends SlashCommand {
    public get build(): SlashCommandBuilder {
        return new SlashCommandBuilder()
            .setName("test")
            .setDescription("yes this is a test!");
    }

    public async run(): Promise<void> {
        await this.context!.reply("yes!")
    }
}