@@ -29,6 +29,7 @@ import { CommandRegistrar } from '../register/CommandRegistrar';
2929import { Command , Middleware } from '../router' ;
3030import { getConfig } from '../../config/config' ;
3131import { beforeExecute , middlewareId } from '../middlewares/permissions' ;
32+ import { isInteractionSource } from '../commands/helpers' ;
3233
3334const KNOWN_NON_HANDLER_KEYS = [
3435 'command' ,
@@ -516,7 +517,14 @@ export class AppCommandHandler {
516517 }
517518
518519 // 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 ) ;
520528 if ( ! loadedCommand ) return null ;
521529
522530 // If this is a guild specific command, check if we're in the right guild
@@ -570,10 +578,22 @@ export class AppCommandHandler {
570578 /**
571579 * Finds a command by name.
572580 * @param name - The command name to search for
581+ * @param hint - The hint for the command type (user or message)
573582 * @returns The loaded command or null if not found
574583 */
575- private findCommandByName ( name : string ) : LoadedCommand | null {
584+ private findCommandByName (
585+ name : string ,
586+ hint ?: 'user' | 'message' ,
587+ ) : LoadedCommand | null {
576588 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+
577597 if ( loadedCommand . data . command . name === name ) {
578598 return loadedCommand ;
579599 }
@@ -584,6 +604,7 @@ export class AppCommandHandler {
584604 return loadedCommand ;
585605 }
586606 }
607+
587608 return null ;
588609 }
589610
@@ -870,10 +891,14 @@ export class AppCommandHandler {
870891 /**
871892 * Gets the metadata for a command.
872893 * @param command - The command name to get metadata for
894+ * @param hint - The hint for the command type (user or message)
873895 * @returns The command metadata or null if not found
874896 */
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 ) ;
877902 if ( ! loadedCommand ) return null ;
878903
879904 return ( loadedCommand . metadata ??= {
0 commit comments