CommandData & { __metadata?: CommandMetadata; __applyId(id: string): void; })[]) => `} />
Updates the guild commands.
diff --git a/apps/website/docs/api-reference/commandkit/interfaces/loaded-command.mdx b/apps/website/docs/api-reference/commandkit/interfaces/loaded-command.mdx
index 432ef45b..588d84f6 100644
--- a/apps/website/docs/api-reference/commandkit/interfaces/loaded-command.mdx
+++ b/apps/website/docs/api-reference/commandkit/interfaces/loaded-command.mdx
@@ -19,6 +19,7 @@ Represents a loaded command with its metadata and configuration.
```ts title="Signature"
interface LoadedCommand {
+ discordId: string | null;
command: Command;
metadata: CommandMetadata;
data: AppCommand;
@@ -27,21 +28,27 @@ interface LoadedCommand {
+### discordId
+
+
+
+The associated discord snowflake id for this command.
+If the information is not yet available, this will be `null`.
### command
Command`} />
-
+The command data.
### metadata
CommandMetadata`} />
-
+The metadata for this command.
### data
AppCommand`} />
-
+The data for this command.
diff --git a/apps/website/docs/api-reference/commandkit/interfaces/prepared-app-command-execution.mdx b/apps/website/docs/api-reference/commandkit/interfaces/prepared-app-command-execution.mdx
index 063dda82..09437062 100644
--- a/apps/website/docs/api-reference/commandkit/interfaces/prepared-app-command-execution.mdx
+++ b/apps/website/docs/api-reference/commandkit/interfaces/prepared-app-command-execution.mdx
@@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
## PreparedAppCommandExecution
-
+
Represents a prepared command execution with all necessary data and middleware.
diff --git a/apps/website/docs/api-reference/commandkit/types/command-builder-like.mdx b/apps/website/docs/api-reference/commandkit/types/command-builder-like.mdx
index a75f6b51..8cac8a10 100644
--- a/apps/website/docs/api-reference/commandkit/types/command-builder-like.mdx
+++ b/apps/website/docs/api-reference/commandkit/types/command-builder-like.mdx
@@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
## CommandBuilderLike
-
+
Type representing command builder objects supported by CommandKit.
diff --git a/apps/website/docs/api-reference/commandkit/types/command-type-data.mdx b/apps/website/docs/api-reference/commandkit/types/command-type-data.mdx
index 0df6557c..8159f8d9 100644
--- a/apps/website/docs/api-reference/commandkit/types/command-type-data.mdx
+++ b/apps/website/docs/api-reference/commandkit/types/command-type-data.mdx
@@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
## CommandTypeData
-
+
Type representing command data identifier.
diff --git a/apps/website/docs/api-reference/commandkit/types/resolvable-command.mdx b/apps/website/docs/api-reference/commandkit/types/resolvable-command.mdx
index 6ba3bd91..339edf48 100644
--- a/apps/website/docs/api-reference/commandkit/types/resolvable-command.mdx
+++ b/apps/website/docs/api-reference/commandkit/types/resolvable-command.mdx
@@ -13,7 +13,7 @@ import MemberDescription from '@site/src/components/MemberDescription';
## ResolvableCommand
-
+
Type for commands that can be resolved by the handler.
diff --git a/packages/commandkit/src/app/handlers/AppCommandHandler.ts b/packages/commandkit/src/app/handlers/AppCommandHandler.ts
index 55b716c0..e1da4d1b 100644
--- a/packages/commandkit/src/app/handlers/AppCommandHandler.ts
+++ b/packages/commandkit/src/app/handlers/AppCommandHandler.ts
@@ -90,8 +90,22 @@ interface AppCommandMiddleware {
* Represents a loaded command with its metadata and configuration.
*/
export interface LoadedCommand {
+ /**
+ * The associated discord snowflake id for this command.
+ * If the information is not yet available, this will be `null`.
+ */
+ discordId: string | null;
+ /**
+ * The command data.
+ */
command: Command;
+ /**
+ * The metadata for this command.
+ */
metadata: CommandMetadata;
+ /**
+ * The data for this command.
+ */
data: AppCommand;
}
@@ -787,6 +801,7 @@ export class AppCommandHandler {
// Skip if path is null (directory-only command group) - external plugins
if (command.path === null) {
this.loadedCommands.set(id, {
+ discordId: null,
command,
metadata: {
guilds: [],
@@ -897,6 +912,7 @@ export class AppCommandHandler {
}
this.loadedCommands.set(id, {
+ discordId: null,
command,
metadata: {
guilds: commandJson.guilds,
diff --git a/packages/commandkit/src/app/register/CommandRegistrar.ts b/packages/commandkit/src/app/register/CommandRegistrar.ts
index 2f3564c2..3e96969c 100644
--- a/packages/commandkit/src/app/register/CommandRegistrar.ts
+++ b/packages/commandkit/src/app/register/CommandRegistrar.ts
@@ -37,7 +37,10 @@ export class CommandRegistrar {
/**
* Gets the commands data.
*/
- public getCommandsData(): (CommandData & { __metadata?: CommandMetadata })[] {
+ public getCommandsData(): (CommandData & {
+ __metadata?: CommandMetadata;
+ __applyId(id: string): void;
+ })[] {
const handler = this.commandkit.commandHandler;
// Use the public method instead of accessing private property
const commands = handler.getCommandsArray();
@@ -50,8 +53,10 @@ export class CommandRegistrar {
const __metadata = cmd.metadata ?? cmd.data.metadata;
- const collections: (CommandData & { __metadata?: CommandMetadata })[] =
- [];
+ const collections: (CommandData & {
+ __metadata?: CommandMetadata;
+ __applyId(id: string): void;
+ })[] = [];
if (cmd.data.chatInput) {
collections.push({
@@ -59,6 +64,9 @@ export class CommandRegistrar {
type: ApplicationCommandType.ChatInput,
description: json.description ?? 'No command description set.',
__metadata,
+ __applyId: (id: string) => {
+ cmd.discordId = id;
+ },
});
}
@@ -72,6 +80,9 @@ export class CommandRegistrar {
description_localizations: undefined,
description: undefined,
__metadata,
+ __applyId: (id: string) => {
+ cmd.discordId = id;
+ },
});
}
@@ -84,6 +95,9 @@ export class CommandRegistrar {
description: undefined,
options: undefined,
__metadata,
+ __applyId: (id: string) => {
+ cmd.discordId = id;
+ },
});
}
@@ -138,7 +152,10 @@ export class CommandRegistrar {
* Updates the global commands.
*/
public async updateGlobalCommands(
- commands: (CommandData & { __metadata?: CommandMetadata })[],
+ commands: (CommandData & {
+ __metadata?: CommandMetadata;
+ __applyId(id: string): void;
+ })[],
) {
if (!commands.length) return;
@@ -162,9 +179,20 @@ export class CommandRegistrar {
body: commands.map((c) => ({
...c,
__metadata: undefined,
+ __applyId: undefined,
})),
},
- )) as CommandData[];
+ )) as (CommandData & { id: string })[];
+
+ // inject the command id into the command
+ data.forEach((c) => {
+ if (!c.id) return;
+ const cmd = commands.find(
+ (co) => co.name === c.name && co.type === c.type,
+ );
+ if (!cmd) return;
+ cmd.__applyId?.(c.id);
+ });
Logger.info(
`✨ Refreshed ${data.length} global application (/) commands`,
@@ -178,7 +206,10 @@ export class CommandRegistrar {
* Updates the guild commands.
*/
public async updateGuildCommands(
- commands: (CommandData & { __metadata?: CommandMetadata })[],
+ commands: (CommandData & {
+ __metadata?: CommandMetadata;
+ __applyId(id: string): void;
+ })[],
) {
if (!commands.length) return;
@@ -242,9 +273,19 @@ export class CommandRegistrar {
body: guildCommands.map((b) => ({
...b,
__metadata: undefined,
+ __applyId: undefined,
})),
},
- )) as CommandData[];
+ )) as (CommandData & { id: string })[];
+
+ data.forEach((c) => {
+ if (!c.id) return;
+ const cmd = commands.find(
+ (co) => co.name === c.name && co.type === c.type,
+ );
+ if (!cmd) return;
+ cmd.__applyId?.(c.id);
+ });
count += data.length;
}