Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: option register command on start #10

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/three-berries-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@softnetics/what-is-dis": minor
---

Add reregister command to bot
12 changes: 11 additions & 1 deletion packages/what-is-dis/src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ interface DiscordBotOptions {
* The callback before the bot shut down.
*/
onShutDown?: (args: { logger: Logger; client: Client }) => void
/**
* If true the bot will register the slash commands on start. Defaults to true.
*/
registerCommandsOnStart?: boolean
}

export class DiscordBot {
Expand All @@ -66,6 +70,10 @@ export class DiscordBot {
private readonly slashCommandCollection = new Collection<string, SlashCommand>()

constructor(private readonly options: DiscordBotOptions) {
if (options.registerCommandsOnStart === undefined) {
options.registerCommandsOnStart = true
}

this.logger = createLogger('bot', this.options.loggerOptions)
this.rest = new REST({ version: '10', timeout: 2000 }).setToken(options.token)
const intents = options.intents.reduce((acc, cur) => acc | cur, 0)
Expand Down Expand Up @@ -181,7 +189,9 @@ export class DiscordBot {
async listen() {
this.setupGracefulShutdown()
this.subscribeGatewayDispatchEvents()
await this.registerSlashCommands()
if (this.options.registerCommandsOnStart) {
await this.registerSlashCommands()
}
this.logger.info("Bot's logging in...")
await this.client.login(this.options.token)
this.logger.info("Bot's ready!")
Expand Down