Receive Sub Command? #1227
Answered
by
civilCornball
civilCornball
asked this question in
Q&A
-
I have, absolutely no idea how to receive a sub command of an existing slash command. Maybe it has something to do with |
Beta Was this translation helpful? Give feedback.
Answered by
civilCornball
May 24, 2024
Replies: 1 comment 1 reply
-
You will have to create option of type sub command and put it inside your command definition. Example sub command is a user selection: $userOption = new Option($discord);
$userOption
->setName('user')
->setType(Option::USER);
$subcommand = new Option($discord);
$subcommand->setName('sub')
->setDescription('This is a sub command');
->setType(Option::SUBCOMMAND);
->addOption($userOption);
$command->addOption($subcommand); commandstring submitted this example last year in our Discord: function getOptionFromInteraction(\Discord\Helpers\Collection|\Discord\Parts\Interactions\Interaction $options, string ...$names): ?\Discord\Parts\Interactions\Request\Option
{
if ($options instanceof Interaction) $options = $options->data->options;
foreach ($names as $key => $name) {
$option = $options->get("name", $name);
if ($key !== count($names)-1) $options = $option?->options;
if (is_null($options) || is_null($option)) break;
}
return $option;
}
getOptionFromInteraction($interaction, "nameOfSubCommand", "nameOfOptionInSubCommand");
getOptionFromInteraction($interaction->data->options->get("name", "nameOfSubCommand"), "nameOfOptionInSubCommand"); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems that subcommand options are located within this:
Interaction $interaction->data->options->first()->options;
The example valzargaming gave helped, of course.