Skip to content

Commit f5d618a

Browse files
authored
feat: add option (#10)
1 parent aa6472c commit f5d618a

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@softnetics/what-is-dis": minor
3+
---
4+
5+
Add reregister command to bot

packages/what-is-dis/src/bot/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ interface DiscordBotOptions {
5454
* The callback before the bot shut down.
5555
*/
5656
onShutDown?: (args: { logger: Logger; client: Client }) => void
57+
/**
58+
* If true the bot will register the slash commands on start. Defaults to true.
59+
*/
60+
registerCommandsOnStart?: boolean
5761
}
5862

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

6872
constructor(private readonly options: DiscordBotOptions) {
73+
if (options.registerCommandsOnStart === undefined) {
74+
options.registerCommandsOnStart = true
75+
}
76+
6977
this.logger = createLogger('bot', this.options.loggerOptions)
7078
this.rest = new REST({ version: '10', timeout: 2000 }).setToken(options.token)
7179
const intents = options.intents.reduce((acc, cur) => acc | cur, 0)
@@ -181,7 +189,9 @@ export class DiscordBot {
181189
async listen() {
182190
this.setupGracefulShutdown()
183191
this.subscribeGatewayDispatchEvents()
184-
await this.registerSlashCommands()
192+
if (this.options.registerCommandsOnStart) {
193+
await this.registerSlashCommands()
194+
}
185195
this.logger.info("Bot's logging in...")
186196
await this.client.login(this.options.token)
187197
this.logger.info("Bot's ready!")

0 commit comments

Comments
 (0)