Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## AppCommandHandler

<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="195" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="194" packageName="commandkit" />

Handles application commands for CommandKit, including loading, registration, and execution.
Manages both slash commands and message commands with middleware support.
Expand All @@ -29,6 +29,7 @@ class AppCommandHandler {
getCommandsArray() => ;
registerCommandHandler() => ;
prepareCommandRun(source: Interaction | Message, cmdName?: string) => Promise<PreparedAppCommandExecution | null>;
resolveMessageCommandName(name: string) => string;
reloadCommands() => ;
addExternalMiddleware(data: Middleware[]) => ;
addExternalCommands(data: Command[]) => ;
Expand Down Expand Up @@ -86,6 +87,11 @@ Registers event handlers for Discord interactions and messages.
<MemberInfo kind="method" type={`(source: Interaction | Message, cmdName?: string) => Promise&#60;<a href='/docs/api-reference/commandkit/interfaces/prepared-app-command-execution#preparedappcommandexecution'>PreparedAppCommandExecution</a> | null&#62;`} />

Prepares a command for execution by resolving the command and its middleware.
### resolveMessageCommandName

<MemberInfo kind="method" type={`(name: string) => string`} />


### reloadCommands

<MemberInfo kind="method" type={`() => `} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## MiddlewareContext

<GenerationInfo sourceFile="packages/commandkit/src/app/commands/Context.ts" sourceLine="569" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/commands/Context.ts" sourceLine="570" packageName="commandkit" />

Extended context class for middleware execution with additional control methods.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## AppCommandNative

<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="55" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="54" packageName="commandkit" />

Represents a native command structure used in CommandKit.
This structure includes the command definition and various handlers for different interaction types.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## CustomAppCommandProps

<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="70" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="69" packageName="commandkit" />

Custom properties that can be added to an AppCommand.
This allows for additional metadata or configuration to be associated with a command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## LoadedCommand

<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="92" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="91" packageName="commandkit" />

Represents a loaded command with its metadata and configuration.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## PreparedAppCommandExecution

<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="134" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="133" packageName="commandkit" />

Represents a prepared command execution with all necessary data and middleware.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## AppCommand

<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="78" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="77" packageName="commandkit" />

Represents a command in the CommandKit application, including its metadata and handlers.
This type extends the native command structure with additional properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## CommandBuilderLike

<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="143" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="142" packageName="commandkit" />

Type representing command builder objects supported by CommandKit.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## CommandTypeData

<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="115" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="114" packageName="commandkit" />

Type representing command data identifier.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## ResolvableCommand

<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="120" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="119" packageName="commandkit" />

Type for commands that can be resolved by the handler.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';

## RunCommand

<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="48" packageName="commandkit" />
<GenerationInfo sourceFile="packages/commandkit/src/app/handlers/AppCommandHandler.ts" sourceLine="47" packageName="commandkit" />

Function type for wrapping command execution with custom logic.

Expand Down
5 changes: 3 additions & 2 deletions packages/commandkit/src/app/commands/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,10 @@ export class Context<
public get commandName(): string {
if (this.isInteraction()) {
return this.interaction.commandName;
} else {
return this.config.messageCommandParser!.getCommand();
}

const maybeAlias = this.config.messageCommandParser!.getCommand();
return this.commandkit.commandHandler.resolveMessageCommandName(maybeAlias);
}

/**
Expand Down
17 changes: 16 additions & 1 deletion packages/commandkit/src/app/handlers/AppCommandHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
ApplicationCommandType,
AutocompleteInteraction,
Awaitable,
Collection,
Expand Down Expand Up @@ -648,6 +647,22 @@ export class AppCommandHandler {
return null;
}

public resolveMessageCommandName(name: string): string {
for (const [, loadedCommand] of this.loadedCommands) {
if (loadedCommand.data.command.name === name) {
return loadedCommand.data.command.name;
}

const aliases = loadedCommand.data.metadata?.aliases;

if (aliases && Array.isArray(aliases) && aliases.includes(name)) {
return loadedCommand.data.command.name;
}
}

return name;
}

/**
* Reloads all commands and middleware from scratch.
*/
Expand Down