Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Discord/Helpers/RegisteredCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Discord/WebSockets/Events/InteractionCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down