@@ -29,6 +29,7 @@ import { CommandRegistrar } from '../register/CommandRegistrar';
29
29
import { Command , Middleware } from '../router' ;
30
30
import { getConfig } from '../../config/config' ;
31
31
import { beforeExecute , middlewareId } from '../middlewares/permissions' ;
32
+ import { isInteractionSource } from '../commands/helpers' ;
32
33
33
34
const KNOWN_NON_HANDLER_KEYS = [
34
35
'command' ,
@@ -516,7 +517,14 @@ export class AppCommandHandler {
516
517
}
517
518
518
519
// Find the command by name
519
- const loadedCommand = this . findCommandByName ( cmdName ) ;
520
+ const hint = isInteractionSource ( source )
521
+ ? source . isUserContextMenuCommand ( )
522
+ ? 'user'
523
+ : source . isMessageContextMenuCommand ( )
524
+ ? 'message'
525
+ : undefined
526
+ : undefined ;
527
+ const loadedCommand = this . findCommandByName ( cmdName , hint ) ;
520
528
if ( ! loadedCommand ) return null ;
521
529
522
530
// If this is a guild specific command, check if we're in the right guild
@@ -570,10 +578,22 @@ export class AppCommandHandler {
570
578
/**
571
579
* Finds a command by name.
572
580
* @param name - The command name to search for
581
+ * @param hint - The hint for the command type (user or message)
573
582
* @returns The loaded command or null if not found
574
583
*/
575
- private findCommandByName ( name : string ) : LoadedCommand | null {
584
+ private findCommandByName (
585
+ name : string ,
586
+ hint ?: 'user' | 'message' ,
587
+ ) : LoadedCommand | null {
576
588
for ( const [ , loadedCommand ] of this . loadedCommands ) {
589
+ if ( hint ) {
590
+ const nameAliases = loadedCommand . data . metadata ?. nameAliases ;
591
+
592
+ if ( nameAliases && nameAliases [ hint ] === name ) {
593
+ return loadedCommand ;
594
+ }
595
+ }
596
+
577
597
if ( loadedCommand . data . command . name === name ) {
578
598
return loadedCommand ;
579
599
}
@@ -584,6 +604,7 @@ export class AppCommandHandler {
584
604
return loadedCommand ;
585
605
}
586
606
}
607
+
587
608
return null ;
588
609
}
589
610
@@ -870,10 +891,14 @@ export class AppCommandHandler {
870
891
/**
871
892
* Gets the metadata for a command.
872
893
* @param command - The command name to get metadata for
894
+ * @param hint - The hint for the command type (user or message)
873
895
* @returns The command metadata or null if not found
874
896
*/
875
- public getMetadataFor ( command : string ) : CommandMetadata | null {
876
- const loadedCommand = this . findCommandByName ( command ) ;
897
+ public getMetadataFor (
898
+ command : string ,
899
+ hint ?: 'user' | 'message' ,
900
+ ) : CommandMetadata | null {
901
+ const loadedCommand = this . findCommandByName ( command , hint ) ;
877
902
if ( ! loadedCommand ) return null ;
878
903
879
904
return ( loadedCommand . metadata ??= {
0 commit comments