Autocomplete
How to create discord autocomplete commands
Creating autocomplete options
Imagine that you want to provide choices for a command option but in a dynamic way, for example a command to search for videos on YouTube. You can use the autocomplete
option, so that based on what the user types in that option, you can search APIs and return a list of choices.
It's required have a slash command to create an autocomplete option
You can create an autocomplete option in your command and respond to it using the autocomplete
method above run
Note that you can only return options, as the autocomplete command handler will automatically limit the array items to 25
Here's what the internal function of the autocomplete command handler looks like:
If you have a large number of items, use autocomplete to try to find it
If you prefer, you can use the interaction's respond
method as you normally would: