AutocompleteHandler

@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class AutocompleteHandler(val name: String = "", val mode: AutocompleteMode = AutocompleteMode.FUZZY, val showUserInput: Boolean = false)(source)

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 annotated method must return a Collection, which gets processed differently based on its element type:

  • String, Long, Double: Makes a choice where name == value, uses fuzzy matching to give the best choices first

  • Choice: 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 must be named the same as in the original slash command.

  • The parameters of the same name must have the same type as the original slash command.

  • The parameters can be in any order, include custom parameters or omit options.

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

Properties

Link copied to clipboard
Link copied to clipboard
@get:JvmName(name = "value")
val name: String

Sets the name of the autocomplete handler, it must be the same as what you set in SlashOption.autocomplete.

Link copied to clipboard
val showUserInput: Boolean = false

Whether the user input is shown as the first suggestion.