Skip to main content

Class: Subcommand<PreParseReturn, Options>

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:37

The class to extends for commands that have subcommands. Specify the subcommands through the Subcommand.Options.subcommands option.

Note that you should not make all your commands extend this class, only the ones that have subcommands. The reason for this is that this class implements Command.messageRun and Command.chatInputRun which you wouldn't necessarily want to do for commands that don't have subcommands. Furthermore, it also just adds general unnecessary memory overhead.

Extends

  • Command<PreParseReturn, Options>

Type Parameters

Type ParameterDefault type
PreParseReturn extends ArgsArgs
Options extends OptionsOptions

Constructors

new Subcommand()

new Subcommand<PreParseReturn, Options>(context: LoaderContext, options: Options): Subcommand<PreParseReturn, Options>

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:59

Parameters

ParameterType
contextLoaderContext
optionsOptions

Returns

Subcommand<PreParseReturn, Options>

Overrides

Command< PreParseReturn, Options >.constructor

Properties

aliases

aliases: readonly string[]

Defined in: node_modules/@sapphire/pieces/dist/esm/index.d.mts:877

The aliases for the piece.

Inherited from

Command.aliases


applicationCommandRegistry

readonly applicationCommandRegistry: ApplicationCommandRegistry

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:963

The application command registry associated with this command.

Since

3.0.0

Inherited from

Command.applicationCommandRegistry


caseInsensitiveSubcommands

caseInsensitiveSubcommands: boolean = false

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:57

Whether to use case insensitive subcommands. This is only relevant for message-command styled commands as chat input commands are always lowercase. This can be enabled through clientOptions.caseInsensitiveCommands.


description

description: string

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:925

A basic summary about the command

Since

1.0.0

Inherited from

Command.description


detailedDescription

detailedDescription: DetailedDescriptionCommand

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:935

Longer version of command's summary and how to use it

Since

1.0.0

Inherited from

Command.detailedDescription


enabled

enabled: boolean

Defined in: node_modules/@sapphire/pieces/dist/esm/index.d.mts:234

Whether or not the piece is enabled.

Inherited from

Command.enabled


fullCategory

readonly fullCategory: readonly string[]

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:947

The full category for the command, can be overridden by setting the Command.Options.fullCategory option.

If Command.Options.fullCategory is not set, then:

  • If the command is loaded from the file system, then this is the command's location in file system relative to the commands folder. For example, if you have a command located at commands/General/Information/info.ts then this property will be ['General', 'Info'].
  • If the command is virtual, then this will be [].

Since

2.0.0

Inherited from

Command.fullCategory


lexer

private lexer: Lexer

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:969

The lexer to be used for command parsing

Since

1.0.0

Inherited from

Command.lexer


location

readonly location: PieceLocation

Defined in: node_modules/@sapphire/pieces/dist/esm/index.d.mts:226

The location metadata for the piece's file.

Inherited from

Command.location


name

readonly name: string

Defined in: node_modules/@sapphire/pieces/dist/esm/index.d.mts:230

The name of the piece.

Inherited from

Command.name


options

readonly options: Options

Defined in: node_modules/@sapphire/pieces/dist/esm/index.d.mts:238

The raw options passed to this Piece

Inherited from

Command.options


parsedSubcommandMappings

parsedSubcommandMappings: SubcommandMappingArray

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:51

The parsed subcommand mappings that were provided with the SubcommandOptions.subcommands option. This is built at construction time and is used to determine which subcommand to run.


preconditions

preconditions: PreconditionContainerArray

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:930

The preconditions to be run.

Since

1.0.0

Inherited from

Command.preconditions


rawName

rawName: string

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:920

The raw name of the command as provided through file name or constructor options.

This is exactly what is set by the developer, completely unmodified internally by the framework. Unlike the name which gets lowercased for storing it uniquely in the CommandStore.

Inherited from

Command.rawName


store

readonly store: CommandStore

Defined in: node_modules/@sapphire/pieces/dist/esm/index.d.mts:222

The store that contains the piece.

Inherited from

Command.store


strategy

strategy: IUnorderedStrategy

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:952

The strategy to use for the lexer.

Since

1.0.0

Inherited from

Command.strategy


subcommandPreconditions

readonly subcommandPreconditions: Map<string, PreconditionContainerArray>

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:45

The preconditions to be run for each specified subcommand.

Since

4.1.0


typing

typing: boolean

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:958

If SapphireClient.typing is true, it can be overridden for a specific command using this property, set via its options. Otherwise, this property will be ignored.

Default

true

Inherited from

Command.typing

Accessors

category

Get Signature

get category(): null | string

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:991

The main category for the command, if any.

This getter retrieves the first value of Command.fullCategory, if it has at least one item, otherwise it returns null.

Note

You can set Command.Options.fullCategory to override the built-in category resolution.

Returns

null | string

Inherited from

Command.category


container

Get Signature

get container(): Container

Defined in: node_modules/@sapphire/pieces/dist/esm/index.d.mts:244

A reference to the Container object for ease of use.

See

container

Returns

Container

Inherited from

Command.container


parentCategory

Get Signature

get parentCategory(): null | string

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1009

The parent category for the command.

This getter retrieves the last value of Command.fullCategory, if it has at least one item, otherwise it returns null.

Note

You can set Command.Options.fullCategory to override the built-in category resolution.

Returns

null | string

Inherited from

Command.parentCategory


subCategory

Get Signature

get subCategory(): null | string

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1000

The sub-category for the command, if any.

This getter retrieves the second value of Command.fullCategory, if it has at least two items, otherwise it returns null.

Note

You can set Command.Options.fullCategory to override the built-in category resolution.

Returns

null | string

Inherited from

Command.subCategory

Methods

#findSubcommand()

private #findSubcommand(mappings: SubcommandMappingMethod[], expectedName: string): { defaultMatch: false; mapping: SubcommandMappingMethod; } | { defaultMatch: true; mapping: null | SubcommandMappingMethod; }

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:537

Parameters

ParameterType
mappingsSubcommandMappingMethod[]
expectedNamestring

Returns

{ defaultMatch: false; mapping: SubcommandMappingMethod; } | { defaultMatch: true; mapping: null | SubcommandMappingMethod; }


#getCommandPrefix()

private #getCommandPrefix(content: string, prefix: string | RegExp): string

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:390

Parameters

ParameterType
contentstring
prefixstring | RegExp

Returns

string


#getMessageParametersAsString()

private #getMessageParametersAsString(args: Args): Promise<Partial<Pick<MessageCommandDeniedPayload, "parameters">>>

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:394

Parameters

ParameterType
argsArgs

Returns

Promise<Partial<Pick<MessageCommandDeniedPayload, "parameters">>>


#handleChatInputInteractionRun()

private #handleChatInputInteractionRun(interaction: Interaction, context: ChatInputCommandContext, subcommand: SubcommandMappingMethod, subcommandGroupName: undefined | string): Promise<void>

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:474

Parameters

ParameterType
interactionInteraction
contextChatInputCommandContext
subcommandSubcommandMappingMethod
subcommandGroupNameundefined | string

Returns

Promise<void>


#handleMessageRun()

private #handleMessageRun(message: Message, args: Args, context: MessageCommandContext, subcommand: SubcommandMappingMethod, subcommandGroupName: undefined | string): Promise<void>

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:408

Parameters

ParameterType
messageMessage
argsArgs
contextMessageCommandContext
subcommandSubcommandMappingMethod
subcommandGroupNameundefined | string

Returns

Promise<void>


#supportsCommandType()

private #supportsCommandType(commandType: "chatInputRun" | "messageRun"): boolean

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:555

Parameters

ParameterType
commandType"chatInputRun" | "messageRun"

Returns

boolean


autocompleteRun()?

optional autocompleteRun(interaction: AutocompleteInteraction): unknown

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1041

Executes the autocomplete logic.

tip

You may use this, or alternatively create an InteractionHandler interaction handler to handle autocomplete interactions. Keep in mind that commands take precedence over interaction handlers.

Parameters

ParameterTypeDescription
interactionAutocompleteInteractionThe interaction that triggered the autocomplete.

Returns

unknown

Inherited from

Command.autocompleteRun


chatInputRun()

chatInputRun(interaction: Interaction, context: ChatInputCommandContext): Promise<void>

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:352

The method that is ran when a chat input based subcommand is ran.

DO NOT override this in your implementation of a subcommand!

Parameters

ParameterType
interactionInteraction
contextChatInputCommandContext

Returns

Promise<void>

Overrides

Command.chatInputRun


contextMenuRun()?

optional contextMenuRun(interaction: ContextMenuCommandInteraction, context: ContextMenuCommandContext): unknown

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1028

Executes the context menu's logic.

Parameters

ParameterTypeDescription
interactionContextMenuCommandInteractionThe interaction that triggered the command.
contextContextMenuCommandContextThe context menu command run context.

Returns

unknown

Inherited from

Command.contextMenuRun


messagePreParse()

messagePreParse(message: Message, parameters: string, context: MessageCommandContext): Awaitable<PreParseReturn>

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:982

The message pre-parse method. This method can be overridden by plugins to define their own argument parser.

Parameters

ParameterTypeDescription
messageMessageThe message that triggered the command.
parametersstringThe raw parameters as a single string.
contextMessageCommandContextThe command-context used in this execution.

Returns

Awaitable<PreParseReturn>

Inherited from

Command.messagePreParse


messageRun()

messageRun(message: Message, args: PreParseReturn, context: MessageCommandContext): Promise<void>

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:253

The method that is ran when a message-based subcommand is ran.

DO NOT override this in your implementation of a subcommand!

Parameters

ParameterType
messageMessage
argsPreParseReturn
contextMessageCommandContext

Returns

Promise<void>

Overrides

Command.messageRun


onLoad()

onLoad(): void

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:221

Per-piece listener that is called when the piece is loaded into the store. Useful to set-up asynchronous initialization tasks.

Returns

void

Overrides

Command.onLoad


onUnload()

onUnload(): unknown

Defined in: node_modules/@sapphire/pieces/dist/esm/index.d.mts:254

Per-piece listener that is called when the piece is unloaded from the store. Useful to set-up clean-up tasks.

Returns

unknown

Inherited from

Command.onUnload


parseConstructorPreConditions()

protected parseConstructorPreConditions(options: CommandOptions): void

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1076

Parses the command's options and processes them, calling Command#parseConstructorPreConditionsRunIn, Command#parseConstructorPreConditionsNsfw, Command#parseConstructorPreConditionsRequiredClientPermissions, and Command#parseConstructorPreConditionsCooldown.

Parameters

ParameterTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Since

2.0.0

Inherited from

Command.parseConstructorPreConditions


parseConstructorPreConditionsCooldown()

protected parseConstructorPreConditionsCooldown(options: CommandOptions): void

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1105

Appends the Cooldown precondition when Command.Options.cooldownLimit and Command.Options.cooldownDelay are both non-zero.

Parameters

ParameterTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Inherited from

Command.parseConstructorPreConditionsCooldown


parseConstructorPreConditionsNsfw()

protected parseConstructorPreConditionsNsfw(options: CommandOptions): void

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1081

Appends the NSFW precondition if Command.Options.nsfw is set to true.

Parameters

ParameterTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Inherited from

Command.parseConstructorPreConditionsNsfw


parseConstructorPreConditionsRequiredClientPermissions()

protected parseConstructorPreConditionsRequiredClientPermissions(options: CommandOptions): void

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1093

Appends the ClientPermissions precondition when Command.Options.requiredClientPermissions resolves to a non-zero bitfield.

Parameters

ParameterTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Inherited from

Command.parseConstructorPreConditionsRequiredClientPermissions


parseConstructorPreConditionsRequiredUserPermissions()

protected parseConstructorPreConditionsRequiredUserPermissions(options: CommandOptions): void

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1099

Appends the UserPermissions precondition when Command.Options.requiredUserPermissions resolves to a non-zero bitfield.

Parameters

ParameterTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Inherited from

Command.parseConstructorPreConditionsRequiredUserPermissions


parseConstructorPreConditionsRunIn()

protected parseConstructorPreConditionsRunIn(options: CommandOptions): void

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1087

Appends the RunIn precondition based on the values passed, defaulting to null, which doesn't add a precondition.

Parameters

ParameterTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Inherited from

Command.parseConstructorPreConditionsRunIn


registerApplicationCommands()?

optional registerApplicationCommands(registry: ApplicationCommandRegistry): Awaitable<void>

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1050

Registers the application commands that should be handled by this command.

Parameters

ParameterTypeDescription
registryApplicationCommandRegistryThis command's registry

Returns

Awaitable<void>

Inherited from

Command.registerApplicationCommands


reload()

reload(): Promise<void>

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1067

Reloads the piece by loading the same path in the store.

Returns

Promise<void>

Inherited from

Command.reload


resolveConstructorPreConditionsRunType()

protected resolveConstructorPreConditionsRunType(types: CommandRunInUnion): null | readonly ChannelType[]

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1111

Resolves the Command.Options.runIn option into a Command.RunInTypes array.

Parameters

ParameterTypeDescription
typesCommandRunInUnionThe types to resolve.

Returns

null | readonly ChannelType[]

The resolved types, or null if no types were resolved.

Inherited from

Command.resolveConstructorPreConditionsRunType


supportsAutocompleteInteractions()

supportsAutocompleteInteractions(): this is AutocompleteCommand

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1066

Type-guard that ensures the command supports handling autocomplete interactions by checking if the handler for it is present

Returns

this is AutocompleteCommand

Inherited from

Command.supportsAutocompleteInteractions


supportsChatInputCommands()

supportsChatInputCommands(): this is ChatInputCommand

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:244

Whether this command has chat input subcommands or not

Returns

this is ChatInputCommand

true if this command has chat input subcommands, otherwise false

Overrides

Command.supportsChatInputCommands


supportsContextMenuCommands()

supportsContextMenuCommands(): this is ContextMenuCommand

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1062

Type-guard that ensures the command supports context menu commands by checking if the handler for it is present

Returns

this is ContextMenuCommand

Inherited from

Command.supportsContextMenuCommands


supportsMessageCommands()

supportsMessageCommands(): this is MessageCommand

Defined in: projects/plugins/packages/subcommands/src/lib/Subcommand.ts:236

Whether this command has message-based subcommands or not

Returns

this is MessageCommand

true if this command has message-based subcommands, otherwise false

Overrides

Command.supportsMessageCommands


toJSON()

toJSON(): CommandJSON

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1045

Defines the JSON.stringify behavior of the command.

Returns

CommandJSON

Inherited from

Command.toJSON


unload()

unload(): Promise<void>

Defined in: node_modules/@sapphire/pieces/dist/esm/index.d.mts:258

Unloads and disables the piece.

Returns

Promise<void>

Inherited from

Command.unload


runInTypeIsSpecificsObject()

static runInTypeIsSpecificsObject(types: CommandRunInUnion | CommandSpecificRunIn): types is CommandSpecificRunIn

Defined in: node_modules/@sapphire/framework/dist/esm/index.d.mts:1112

Parameters

ParameterType
typesCommandRunInUnion | CommandSpecificRunIn

Returns

types is CommandSpecificRunIn

Inherited from

Command.runInTypeIsSpecificsObject