Skip to content

Autocomplete handler is not called on subcommands #1413

@codemasher

Description

@codemasher

Environment

  • PHP Version:
    • 8.4.8
  • DiscordPHP Version:
    • 10.36.7

Describe the bug
The autocomplete handler is not properly called when the called command is a subcommand. Autocomplete works perfectly fine on commands without subcommands.

To Reproduce
See below.

Expected behavior
See below.

Additional context
I've tracked down the issue to this method, where I var_dump-ed the $option->focused value and it seemed to have not properly assigned in the options instance:

if ($subCommand = $command->getSubCommand($option->name)) {
if ($option->focused) {
return $subCommand->suggest($interaction);
}
if (! empty($option->options)) {
return $this->checkCommand($subCommand, $option->options, $interaction);
}
} elseif ($option->focused) {

The option value is focused => true as expected and the $subCommand->suggest(...) should be called properly, but the call to $option->focused returns null - I'm not sure where exactly to fix this.

object(Discord\Parts\Interactions\Request\Option)#118 (3) {
  ["attributes"]=>
  array(3) {
    ["name"]=>
    string(3) "set"
    ["type"]=>
    int(1)
    ["options"]=>
    array(1) {
      [0]=>
      object(stdClass)#315 (4) {
        ["value"]=>
        string(0) ""
        ["type"]=>
        int(3)
        ["name"]=>
        string(2) "id"
        ["focused"]=>
        bool(true)
      }
    }
  }
  ["created"]=>
  &bool(true)
  ["class"]=>
  string(41) "Discord\Parts\Interactions\Request\Option"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions