Autocomplete `interaction.commandName` when used in a subcommand
What will be the contents of
interaction.commandName
in an autocomplete interaction handler when the invoking interaction came from a subcommand or a subcommand in a group? Is it just baseCommand subCommand
and baseCommand group subCommand
? On a similar note, does interaction.commandId
change for each subcommand?Solution:Jump to solution
So is the
commandName
property on the interaction that gets passed into the interaction handler just the subcommand name then or is it the parents? At this point, you've said both.14 Replies
All subcommands and command group inherit the id of the parent command
That makes sense. What about the name?
The parent command name
So is there any way to differentiate between subcommands in the same command?
With the name, since there can't be 2 subcommands with the same name
Either in a group of commands or directly from the parent command
So the name isn't the parent commands name?
Well, each subcommand has its own name that you can get with .getSubcommand
Solution
So is the
commandName
property on the interaction that gets passed into the interaction handler just the subcommand name then or is it the parents? At this point, you've said both.This property always carries the name of the invoked command, not the subcommands or group of subcommands since they inherit from the invoked command
Sorry if I have confused you 😥
Its all good. If I'm understanding correctly then, in order to determine which subcommand I'm in, I'd need to check
interaction.options.getSubcommand()
.Yees
Alright then. Thanks for the help!
And to differentiate from a direct subcommand of the parent command to one of subcommands group that have the same name check if the subcommand has a subcommand
Yeah that makes sense. I'll probably write a quick util just to extract the full command path so I can check against that for ease of use.