diff --git a/src/Discord/Helpers/RegisteredCommand.php b/src/Discord/Helpers/RegisteredCommand.php index 3cafec30e..b2b95d5cd 100644 --- a/src/Discord/Helpers/RegisteredCommand.php +++ b/src/Discord/Helpers/RegisteredCommand.php @@ -117,13 +117,14 @@ public function execute($options, Interaction $interaction): bool * executes the callback, if given. * * @param ApplicationCommand|ApplicationCommandAutocomplete $interaction + * @param Option $option The option value for the current autocomplete request * * @return bool Whether the command successfully executed. */ - public function suggest(Interaction $interaction): bool + public function suggest(Interaction $interaction, Option $option): bool { if (is_callable($this->autocomplete_callback)) { - $choice = ($this->autocomplete_callback)($interaction); + $choice = ($this->autocomplete_callback)($interaction, $option); if (is_array($choice)) { $interaction->autoCompleteResult($choice); } diff --git a/src/Discord/WebSockets/Events/InteractionCreate.php b/src/Discord/WebSockets/Events/InteractionCreate.php index 20ff4242e..b16e1a32e 100644 --- a/src/Discord/WebSockets/Events/InteractionCreate.php +++ b/src/Discord/WebSockets/Events/InteractionCreate.php @@ -87,7 +87,7 @@ public function handle($data) if (isset($this->discord->application_commands[$command->name])) { $interaction instanceof ApplicationCommand ? $this->discord->application_commands[$command->name]->execute($command->options ?? [], $interaction) - : $this->checkCommand($this->discord->application_commands[$command->name], $command->options, $interaction); + : $this->checkCommand($this->discord->application_commands[$command->name], $command->options ?? [], $interaction); } } @@ -103,19 +103,19 @@ public function handle($data) * * @return bool Returns true if a suggestion was triggered, otherwise false. */ - protected function checkCommand(RegisteredCommand $command, $options, Interaction $interaction): bool + protected function checkCommand(RegisteredCommand $command, iterable $options, Interaction $interaction): bool { foreach ($options as $option) { /** @var ?RegisteredCommand $subCommand */ if ($subCommand = $command->getSubCommand($option->name)) { if ($option->focused) { - return $subCommand->suggest($interaction); + return $subCommand->suggest($interaction, $option); } - if ($option->options) { + if (is_iterable($option->options)) { return $this->checkCommand($subCommand, $option->options, $interaction); } } elseif ($option->focused) { - return $command->suggest($interaction); + return $command->suggest($interaction, $option); } }