Skip to content

Commit 59ea77d

Browse files
committed
command handler register overhaul
1 parent d935e7a commit 59ea77d

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

src/Discord/Helpers/RegisteredCommand.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,28 +177,22 @@ public function getSubCommand(string $name): ?RegisteredCommand
177177
*
178178
* @return static
179179
*/
180-
public function addSubCommand($names, ?callable $callback = null, ?callable $autocomplete_callback = null): RegisteredCommand
180+
public function addSubCommand(array|string $names, ?callable $callback = null, ?callable $autocomplete_callback = null): RegisteredCommand
181181
{
182-
if (! is_array($names)) {
182+
if (is_string($names)) {
183183
$names = [$names];
184184
}
185185

186-
if (count($names) === 1) {
187-
$name = array_shift($names);
188-
if (isset($this->subCommands[$name])) {
189-
throw new \LogicException("The command `{$name}` already exists.");
190-
}
191-
192-
return $this->subCommands[$name] = new static($this->discord, $name, $callback, $autocomplete_callback);
193-
}
186+
foreach($names as $subCommand){
194187

195-
$subCommand = array_shift($names);
188+
if (isset($this->subCommands[$subCommand])) {
189+
throw new \LogicException("The command `{$subCommand}` already exists.");
190+
}
196191

197-
if (! isset($this->subCommands[$subCommand])) {
198-
$this->addSubCommand($subCommand);
192+
$this->subCommands[$subCommand] = new static($this->discord, $subCommand, $callback, $autocomplete_callback);
199193
}
200194

201-
return $this->subCommands[$subCommand]->addSubCommand($names, $callback, $autocomplete_callback);
195+
return $this;
202196
}
203197

204198
/**

0 commit comments

Comments
 (0)