diff options
| author | Max Isom <[email protected]> | 2022-01-19 18:15:12 -0600 |
|---|---|---|
| committer | Max Isom <[email protected]> | 2022-01-19 18:15:12 -0600 |
| commit | 7901fcce3d7d0ce2ec91ba36a3ba9107e8709bff (patch) | |
| tree | 3587d2d2e6c2f7a49118229453cf42f1b0629226 /src/bot.ts | |
| parent | 43baa57c51ce25aadf7b9d5a75a992e6c1edc7da (diff) | |
| download | muse-7901fcce3d7d0ce2ec91ba36a3ba9107e8709bff.tar.xz muse-7901fcce3d7d0ce2ec91ba36a3ba9107e8709bff.zip | |
✨ add autocomplete
Diffstat (limited to 'src/bot.ts')
| -rw-r--r-- | src/bot.ts | 41 |
1 files changed, 27 insertions, 14 deletions
@@ -87,27 +87,40 @@ export default class { }); this.client.on('interactionCreate', async interaction => { - if (!interaction.isButton()) { - return; - } + try { + if (interaction.isButton()) { + const command = this.commandsByButtonId.get(interaction.customId); - const command = this.commandsByButtonId.get(interaction.customId); + if (!command) { + return; + } - if (!command) { - return; - } + if (command.handleButtonInteraction) { + await command.handleButtonInteraction(interaction); + } + } - try { - if (command.handleButtonInteraction) { - await command.handleButtonInteraction(interaction); + if (interaction.isAutocomplete()) { + const command = this.commandsByName.get(interaction.commandName); + + if (!command) { + return; + } + + if (command.handleAutocompleteInteraction) { + await command.handleAutocompleteInteraction(interaction); + } } } catch (error: unknown) { debug(error); - if (interaction.replied || interaction.deferred) { - await interaction.editReply(errorMsg('something went wrong')); - } else { - await interaction.reply({content: errorMsg(error as Error), ephemeral: true}); + // Can't reply with errors for autocomplete queries + if (interaction.isButton()) { + if (interaction.replied || interaction.deferred) { + await interaction.editReply(errorMsg('something went wrong')); + } else { + await interaction.reply({content: errorMsg(error as Error), ephemeral: true}); + } } } }); |
