diff --git a/src/bot/TicTacToeBot.ts b/src/bot/TicTacToeBot.ts index 24b86a05..997e26ce 100644 --- a/src/bot/TicTacToeBot.ts +++ b/src/bot/TicTacToeBot.ts @@ -61,20 +61,28 @@ export default class TicTacToeBot { * @param client discord.js client obbject */ public attachToClient(client: Client): void { - // Handle slash command if enabled - if (this.configuration.command) { - const register = new AppCommandRegister( - client.application!.commands, - this.configuration.command, - this.configuration.commandOptionName ?? 'opponent' - ); - client.on('messageCreate', register.handleDeployMessage.bind(register)); - client.on('interactionCreate', this.command.handleInteraction.bind(this.command)); - } + const onReady = () => { + // Handle slash command if enabled + if (client.application && this.configuration.command) { + const register = new AppCommandRegister( + client.application.commands, + this.configuration.command, + this.configuration.commandOptionName ?? 'opponent' + ); + client.on('messageCreate', register.handleDeployMessage.bind(register)); + client.on('interactionCreate', this.command.handleInteraction.bind(this.command)); + } + + // Handle text command if enabled + if (this.configuration.textCommand) { + client.on('messageCreate', this.command.handleMessage.bind(this.command)); + } + }; - // Handle text command if enabled - if (this.configuration.textCommand) { - client.on('messageCreate', this.command.handleMessage.bind(this.command)); + if (client.readyAt) { + onReady(); + } else { + client.on('ready', onReady.bind(this)); } }