@@ -1933,29 +1933,27 @@ public function getChannel($channel_id): ?Channel
19331933 *
19341934 * @return RegisteredCommand
19351935 */
1936- public function listenCommand ($ names , ?callable $ callback = null , ?callable $ autocomplete_callback = null ): RegisteredCommand
1936+ public function listenCommand (array | string $ names , ?callable $ callback = null , ?callable $ autocomplete_callback = null ): RegisteredCommand
19371937 {
1938- if (! is_array ($ names )) {
1938+ if (is_string ($ names )) {
19391939 $ names = [$ names ];
19401940 }
19411941
1942- // registering base command
1943- if (count ($ names ) === 1 ) {
1944- $ name = array_shift ($ names );
1945- if (isset ($ this ->application_commands [$ name ])) {
1946- throw new \LogicException ("The command ` {$ name }` already exists. " );
1947- }
1942+ $ baseCommand = array_shift ($ names );
19481943
1949- return $ this ->application_commands [$ name ] = new RegisteredCommand ($ this , $ name , $ callback , $ autocomplete_callback );
1944+ if (isset ($ this ->application_commands [$ baseCommand ])) {
1945+ throw new \LogicException ("The command ` {$ baseCommand }` already exists. " );
19501946 }
19511947
1952- $ baseCommand = array_shift ($ names );
1948+ // registering base command
1949+ $ this ->application_commands [$ baseCommand ] = new RegisteredCommand ($ this , $ baseCommand , $ callback , $ autocomplete_callback );
19531950
1954- if (! isset ($ this ->application_commands [$ baseCommand ])) {
1955- $ this ->listenCommand ($ baseCommand );
1951+ // register subcommands
1952+ foreach ($ names as $ subCommand ){
1953+ $ this ->application_commands [$ baseCommand ]->addSubCommand ($ subCommand , $ callback , $ autocomplete_callback );
19561954 }
19571955
1958- return $ this ->application_commands [$ baseCommand ]-> addSubCommand ( $ names , $ callback , $ autocomplete_callback ) ;
1956+ return $ this ->application_commands [$ baseCommand ];
19591957 }
19601958
19611959 /**
0 commit comments