From 2c6a0d6df05e7377c43a68f65f92118810aac903 Mon Sep 17 00:00:00 2001 From: smiley Date: Mon, 6 Oct 2025 05:32:28 +0200 Subject: [PATCH 1/3] fix potential bug (foreach on null) --- src/Discord/WebSockets/Events/InteractionCreate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord/WebSockets/Events/InteractionCreate.php b/src/Discord/WebSockets/Events/InteractionCreate.php index 20ff4242e..5c075ae94 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); } } From ce208293dd81d0830460183bdf923cbf0f5dcb89 Mon Sep 17 00:00:00 2001 From: smiley Date: Mon, 6 Oct 2025 15:52:07 +0200 Subject: [PATCH 2/3] hand over the matched option value into the autocomplete callback --- src/Discord/Helpers/RegisteredCommand.php | 5 +++-- src/Discord/WebSockets/Events/InteractionCreate.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) 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 5c075ae94..4da8ab71d 100644 --- a/src/Discord/WebSockets/Events/InteractionCreate.php +++ b/src/Discord/WebSockets/Events/InteractionCreate.php @@ -109,13 +109,13 @@ protected function checkCommand(RegisteredCommand $command, $options, Interactio /** @var ?RegisteredCommand $subCommand */ if ($subCommand = $command->getSubCommand($option->name)) { if ($option->focused) { - return $subCommand->suggest($interaction); + return $subCommand->suggest($interaction, $option); } if ($option->options) { return $this->checkCommand($subCommand, $option->options, $interaction); } } elseif ($option->focused) { - return $command->suggest($interaction); + return $command->suggest($interaction, $option); } } From fbe99d60eba9db03d09cc2986ebd27c0373fc3c2 Mon Sep 17 00:00:00 2001 From: smiley Date: Mon, 6 Oct 2025 16:40:19 +0200 Subject: [PATCH 3/3] InteractionCreate::checkCommand(): add iterable type hint and check is_iterable() --- src/Discord/WebSockets/Events/InteractionCreate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Discord/WebSockets/Events/InteractionCreate.php b/src/Discord/WebSockets/Events/InteractionCreate.php index 4da8ab71d..b16e1a32e 100644 --- a/src/Discord/WebSockets/Events/InteractionCreate.php +++ b/src/Discord/WebSockets/Events/InteractionCreate.php @@ -103,7 +103,7 @@ 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 */ @@ -111,7 +111,7 @@ protected function checkCommand(RegisteredCommand $command, $options, Interactio if ($option->focused) { return $subCommand->suggest($interaction, $option); } - if ($option->options) { + if (is_iterable($option->options)) { return $this->checkCommand($subCommand, $option->options, $interaction); } } elseif ($option->focused) {