Autocomplete handling in subcommands

I was wondering how would i handle autocomplete interactions inside subcommands? i have a subcommand group the command has autocompletion on some of it's options is it possible to handle autocompletion within the subcommand class or do i have to handle it in the listener?
Solution:
It's the same as a normal command, but instead of just checking the focused option you can check the subcommand and subcommand group too. ```ts public override async autocompleteRun(interaction: Subcommand.AutocompleteInteraction) { const subcommand = interaction.options.getSubcommand();...
Jump to solution
4 Replies
Favna
Favna5mo ago
use interaction.options.getSubcommand in the autocomplete to determine which subcommand is being ran
Xeno™
Xeno™5mo ago
the subcommand class doesn't implement a autocomplete method so i would have to do it manually inside the interaction listener?
Favna
Favna5mo ago
It should be interested from command... But otherwise yes
Solution
KB
KB5mo ago
It's the same as a normal command, but instead of just checking the focused option you can check the subcommand and subcommand group too.
public override async autocompleteRun(interaction: Subcommand.AutocompleteInteraction) {
const subcommand = interaction.options.getSubcommand();

if (subcommand === 'first') {
// stuff
} else if (subcommand === 'second') {
// stuff
}
}
public override async autocompleteRun(interaction: Subcommand.AutocompleteInteraction) {
const subcommand = interaction.options.getSubcommand();

if (subcommand === 'first') {
// stuff
} else if (subcommand === 'second') {
// stuff
}
}