Skip to content

Commit ee037a4

Browse files
committed
Reduce logical ambiguity
1 parent dc4b576 commit ee037a4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/Discord/Discord.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,36 +1925,37 @@ public function getChannel($channel_id): ?Channel
19251925
/**
19261926
* Add listener for incoming application command from interaction.
19271927
*
1928-
* @param string|array $name
1928+
* @param array|string $names
19291929
* @param callable|null $callback
19301930
* @param callable|null $autocomplete_callback
19311931
*
19321932
* @throws \LogicException
19331933
*
19341934
* @return RegisteredCommand
19351935
*/
1936-
public function listenCommand($name, ?callable $callback = null, ?callable $autocomplete_callback = null): RegisteredCommand
1936+
public function listenCommand($names, ?callable $callback = null, ?callable $autocomplete_callback = null): RegisteredCommand
19371937
{
1938-
if (is_array($name) && count($name) == 1) {
1939-
$name = array_shift($name);
1938+
if (! is_array ($names)) {
1939+
$names = [$names];
19401940
}
19411941

19421942
// registering base command
1943-
if (! is_array($name) || count($name) == 1) {
1943+
if (count($names) == 1) {
1944+
$name = array_shift($names);
19441945
if (isset($this->application_commands[$name])) {
19451946
throw new \LogicException("The command `{$name}` already exists.");
19461947
}
19471948

19481949
return $this->application_commands[$name] = new RegisteredCommand($this, $name, $callback, $autocomplete_callback);
19491950
}
19501951

1951-
$baseCommand = array_shift($name);
1952+
$baseCommand = array_shift($names);
19521953

19531954
if (! isset($this->application_commands[$baseCommand])) {
19541955
$this->listenCommand($baseCommand);
19551956
}
19561957

1957-
return $this->application_commands[$baseCommand]->addSubCommand($name, $callback, $autocomplete_callback);
1958+
return $this->application_commands[$baseCommand]->addSubCommand($names, $callback, $autocomplete_callback);
19581959
}
19591960

19601961
/**

0 commit comments

Comments
 (0)