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
2 changes: 1 addition & 1 deletion packages/commandkit/src/CommandKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const onApplicationBootstrapHooks = new Set<BootstrapFunction>();
/**
* Registers a bootstrap hook that will be called when the CommandKit instance is created.
* This is useful for plugins that need to run some code after the CommandKit instance is fully initialized.
* Note that not all commandkit dependiencs are available at this point. It is recommended to use the `onApplicationBootstrap` hook instead,
* Note that not all commandkit dependencies are available at this point. It is recommended to use the `onApplicationBootstrap` hook instead,
* if you need access to the commandkit dependencies.
* @param fn The bootstrap function to register.
* @example ```ts
Expand Down
9 changes: 9 additions & 0 deletions packages/commandkit/src/app/handlers/AppCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Context } from '../commands/Context';
import { MessageCommandParser } from '../commands/MessageCommandParser';
import { CommandRegistrar } from '../register/CommandRegistrar';
import { Command, Middleware } from '../router';
import { getConfig } from '../../config/config';

/**
* Function type for wrapping command execution with custom logic.
Expand Down Expand Up @@ -419,6 +420,12 @@ export class AppCommandHandler {
source: Interaction | Message,
cmdName?: string,
): Promise<PreparedAppCommandExecution | null> {
const config = getConfig();

if (config.disablePrefixCommands && source instanceof Message) {
return null;
}

let parser: MessageCommandParser | undefined;

// Extract command name (and possibly subcommand) from the source
Expand All @@ -429,6 +436,8 @@ export class AppCommandHandler {
const prefix =
await this.commandkit.config.getMessageCommandPrefix(source);

if (!prefix || !prefix.length) return null;

parser = new MessageCommandParser(
source,
Array.isArray(prefix) ? prefix : [prefix],
Expand Down
2 changes: 2 additions & 0 deletions packages/commandkit/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ export function defineConfig(
...defaultConfig.typescript,
...config.typescript,
},
disablePrefixCommands:
config.disablePrefixCommands ?? defaultConfig.disablePrefixCommands,
};

return defined;
Expand Down
1 change: 1 addition & 0 deletions packages/commandkit/src/config/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export const defaultConfig: ResolvedCommandKitConfig = {
production: true,
},
typedCommands: true,
disablePrefixCommands: false,
};
5 changes: 5 additions & 0 deletions packages/commandkit/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ export interface CommandKitConfig {
* @default true
*/
typedCommands?: boolean;
/**
* Whether or not to disable the prefix commands.
* @default false
*/
disablePrefixCommands?: boolean;
}
Loading