diff --git a/src/command.ts b/src/command.ts index 4ef8a64..2334ad0 100644 --- a/src/command.ts +++ b/src/command.ts @@ -1,4 +1,4 @@ -import { PermissionsBitField } from "discord.js"; +import { AutocompleteInteraction, PermissionsBitField } from "discord.js"; import { RESTPostAPIApplicationCommandsJSONBody } from "discord.js"; import { ApplicationCommandOption, ApplicationCommandType, ChatInputCommandInteraction, LocalizationMap, MessageInteraction, PermissionResolvable, UserSelectMenuInteraction } from "discord.js"; @@ -23,6 +23,8 @@ interface Command { abstract execute(interaction: InteractionTypeMap[Type][0]): Promise; + autocomplete?(interaction: Type extends ApplicationCommandType.ChatInput ? AutocompleteInteraction : never ): Promise; + toRESTPostApplicationCommands(): RESTPostAPIApplicationCommandsJSONBody { return { name: this.name, diff --git a/src/interactionManager.ts b/src/interactionManager.ts index 3b7968b..d6ef69a 100644 --- a/src/interactionManager.ts +++ b/src/interactionManager.ts @@ -32,6 +32,13 @@ export default class CommandManager { foundCommand.execute(interaction); return; } + if (interaction.isAutocomplete()) { + const foundCommand = this.commands.find((command) => command.name == interaction.commandName ); + if (!foundCommand) throw new Error(`Unknown command received (${interaction.commandName}). Did you forgot to push updated commands?`); + if (!foundCommand.autocomplete) return; + foundCommand.autocomplete(interaction); + return; + } } bindClient(client: DiscordClient) {