Skip to content

Commit

Permalink
Allow client to be ready after attached to module
Browse files Browse the repository at this point in the history
  • Loading branch information
utarwyn committed Jan 27, 2022
1 parent db4d4b3 commit 6f6a09d
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/bot/TicTacToeBot.ts
Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 6f6a09d

Please sign in to comment.