Skip to content

Commit 440385a

Browse files
committed
fix: resolve correct command name inside context
1 parent 12a4598 commit 440385a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/commandkit/src/app/commands/Context.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,10 @@ export class Context<
302302
public get commandName(): string {
303303
if (this.isInteraction()) {
304304
return this.interaction.commandName;
305-
} else {
306-
return this.config.messageCommandParser!.getCommand();
307305
}
306+
307+
const maybeAlias = this.config.messageCommandParser!.getCommand();
308+
return this.commandkit.commandHandler.resolveMessageCommandName(maybeAlias);
308309
}
309310

310311
/**

packages/commandkit/src/app/handlers/AppCommandHandler.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
ApplicationCommandType,
32
AutocompleteInteraction,
43
Awaitable,
54
Collection,
@@ -648,6 +647,22 @@ export class AppCommandHandler {
648647
return null;
649648
}
650649

650+
public resolveMessageCommandName(name: string): string {
651+
for (const [, loadedCommand] of this.loadedCommands) {
652+
if (loadedCommand.data.command.name === name) {
653+
return loadedCommand.data.command.name;
654+
}
655+
656+
const aliases = loadedCommand.data.metadata?.aliases;
657+
658+
if (aliases && Array.isArray(aliases) && aliases.includes(name)) {
659+
return loadedCommand.data.command.name;
660+
}
661+
}
662+
663+
return name;
664+
}
665+
651666
/**
652667
* Reloads all commands and middleware from scratch.
653668
*/

0 commit comments

Comments
 (0)