Clones the current AutoCompleteKeyBuilder. Throws an error if the path has already been partially built.
const weatherCommandAutoCompleteKey = router.command(
(builder) =>
builder
.setName("weather")
.setDescription("Query weather information!")
// First autocomplete option
.addStringOption((option) =>
option
.setName("city")
.setDescription("City to get the weather for")
.setAutocomplete(true)
)
//Second autocomplete option
.addStringOption((option) =>
option
.setName("unit")
.setDescription("Unit for temperature")
.setAutocomplete(true)
),
(interaction) => handler
const cityAutoCompleteKey = weatherCommandAutoCompleteKey.clone();
const unitAutoCompleteKey = weatherCommandAutoCompleteKey.clone();
router.autocomplete(cityAutoCompleteKey.getAutoCompleteKey("city"), autocompleteMiddleware);
router.autocomplete(unitAutoCompleteKey.getAutoCompleteKey("unit"), autocompleteMiddleware2);
Get an autocomplete key for router.
The option name.
This builder instance for chaining.
const weatherCommandAutoCompleteKey = router.command(
(builder) =>
builder
.setName("weather")
.setDescription("Query weather information!")
.addStringOption((option) =>
option
.setName("city")
.setDescription("City to get the weather for")
.setAutocomplete(true)
)
router.autocomplete(weatherCommandAutoCompleteKey.getAutocompleteKey("city"), autocompleteMiddleware);
Get a subcommand for an autocomplete key from a slash command.
Subcommand name.
This builder instance for chaining.
const musicCommand = router.command(
(builder) =>
builder
.setName("music")
.setDescription("Music related commands")
.addSubcommand((sub) =>
sub
.setName("play")
.setDescription("Play a song")
.addStringOption((option) =>
option
.setName("song")
.setDescription("Song name")
.setAutocomplete(true)
)
), commandMiddleware);
const MusicCommandAutoCompleteKey = musicCommand.getSubCommand("play").getAutocompleteKey("song");
router.autocomplete(MusicCommandAutoCompleteKey, handler)
Get a subcommandgroup for an autocomplete key from a slash command.
const adminCommand = router.command(
(builder) =>
builder
.setName("admin")
.setDescription("Admin utilities")
.addSubcommandGroup((group) =>
group
.setName("user")
.setDescription("User-related commands")
.addSubcommand((sub) =>
sub
.setName("ban")
.setDescription("Ban a user")
.addStringOption((option) =>
option
.setName("reason")
.setDescription("Reason for banning")
.setAutocomplete(true)
)
)
),
commandHandler
);
router.autocomplete(
adminCommand
.getSubCommandGroup("user")
.getSubCommand("ban")
.getAutocompleteKey("reason"), AutoCompleteHandler
);
Builder utility for creating autocomplete keys used by the router’s
autocomplete()
method.This class helps you construct a colon-delimited key that uniquely identifies the path to an option with
autocomplete
enabled in a slash command, including subcommands and subcommand groups.Simply, This class is used to manage and resolve the paths for autocomplete keys in Discord application commands.
Example