Autocomplete Handler
Uses the method as an autocomplete function for slash command options.
The name must be unique; I recommend naming them similarly to: YourClassSimpleName: AutocompletedField
(for example, SlashTag: tagName
).
If a name is unset, the handler is anonymous and can only be referenced on code-declared commands, using SlashCommandOptionBuilder.autocompleteByFunction.
Requirements:
The declaring class must be annotated with @Handler or be an existing @Command class.
The method must be public
The method must be non-static
The first parameter must be CommandAutoCompleteInteractionEvent
The annotated method must return a Collection, which gets processed differently based on its element type:
String
,Long
,Double
: Makes a choice wherename
==value
, uses fuzzy matching to give the best choices firstChoice
: Keeps the same choices in the same order, does not do any matching.Any type supported by an AutocompleteTransformer: Keeps the same order after transformation.
You can add support for more element types with autocomplete transformers.
State-aware autocomplete
You can also use state-aware autocomplete, meaning you can get what the user has inserted in other options.
The requirements are as follows:
The parameters can only be the event + parameters present on the slash command
They must be of the same name, type and nullability as the original slash command
They can only include parameters from the slash command itself, not from nested parameters (aka aggregates)
Note: Parameters refers to method parameters, not Discord options.
Registering more option types
Supported types and modifiers are in ParameterResolver, additional types can be added by implementing SlashParameterResolver.
See also
@SlashOption
@JDASlashCommand
@CacheAutocomplete
DSL equivalent
Properties
Sets the autocomplete mode.
Sets the name of the autocomplete handler, it must be the same as what you set in SlashOption.autocomplete.
Whether the user input is shown as the first suggestion.