Skip to main content

Class: Subcommand<PreParseReturn, Options>

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 parameterValue
PreParseReturn extends ArgsArgs
Options extends OptionsOptions

Constructors

new Subcommand()

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

Parameters

ParameterType
contextLoaderContext
optionsOptions

Returns

Subcommand<PreParseReturn, Options>

Overrides

`Command< PreParseReturn, Options

.constructor`

Source

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

Properties

aliases

aliases: readonly string[]

The aliases for the piece.

Inherited from

Command.aliases

Source

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


applicationCommandRegistry

readonly applicationCommandRegistry: ApplicationCommandRegistry

The application command registry associated with this command.

Since

3.0.0

Inherited from

Command.applicationCommandRegistry

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:962


caseInsensitiveSubcommands

caseInsensitiveSubcommands: boolean = false

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.

Source

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


description

description: string

A basic summary about the command

Since

1.0.0

Inherited from

Command.description

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:924


detailedDescription

detailedDescription: DetailedDescriptionCommand

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

Since

1.0.0

Inherited from

Command.detailedDescription

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:934


enabled

enabled: boolean

Whether or not the piece is enabled.

Inherited from

Command.enabled

Source

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


fullCategory

readonly fullCategory: readonly string[]

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:946


lexer

private lexer: Lexer

The lexer to be used for command parsing

Since

1.0.0

Inherited from

Command.lexer

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:968


location

readonly location: PieceLocation

The location metadata for the piece's file.

Inherited from

Command.location

Source

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


name

readonly name: string

The name of the piece.

Inherited from

Command.name

Source

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


options

readonly options: Options

The raw options passed to this Piece

Inherited from

Command.options

Source

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


parsedSubcommandMappings

parsedSubcommandMappings: SubcommandMappingArray

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.

Source

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


preconditions

preconditions: PreconditionContainerArray

The preconditions to be run.

Since

1.0.0

Inherited from

Command.preconditions

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:929


rawName

rawName: string

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:919


store

readonly store: CommandStore

The store that contains the piece.

Inherited from

Command.store

Source

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


strategy

strategy: IUnorderedStrategy

The strategy to use for the lexer.

Since

1.0.0

Inherited from

Command.strategy

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:951


subcommandPreconditions

readonly subcommandPreconditions: Map<string, PreconditionContainerArray>

The preconditions to be run for each specified subcommand.

Since

4.1.0

Source

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


typing

typing: boolean

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:957

Accessors

category

get category(): null | string

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:990


container

get container(): Container

A reference to the Container object for ease of use.

See

container

Returns

Container

Source

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


parentCategory

get parentCategory(): null | string

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1008


subCategory

get subCategory(): null | string

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:999

Methods

#findSubcommand()

private #findSubcommand(mappings: SubcommandMappingMethod[], expectedName: string): object | object

Parameters

ParameterType
mappingsSubcommandMappingMethod[]
expectedNamestring

Returns

object | object

Source

projects/plugins/packages/subcommands/src/lib/Subcommand.ts:530


#getMessageParametersAsString()

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

Parameters

ParameterType
argsArgs

Returns

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

Source

projects/plugins/packages/subcommands/src/lib/Subcommand.ts:387


#handleChatInputInteractionRun()

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

Parameters

ParameterType
interactionInteraction <CacheType>
contextChatInputCommandContext
subcommandSubcommandMappingMethod
subcommandGroupNameundefined | string

Returns

Promise<void>

Source

projects/plugins/packages/subcommands/src/lib/Subcommand.ts:467


#handleMessageRun()

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

Parameters

ParameterType
messageMessage<boolean>
argsArgs
contextMessageCommandContext
subcommandSubcommandMappingMethod
subcommandGroupNameundefined | string

Returns

Promise<void>

Source

projects/plugins/packages/subcommands/src/lib/Subcommand.ts:401


#supportsCommandType()

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

Parameters

ParameterType
commandType"chatInputRun" | "messageRun"

Returns

boolean

Source

projects/plugins/packages/subcommands/src/lib/Subcommand.ts:548


autocompleteRun()?

optional autocompleteRun(interaction: AutocompleteInteraction <CacheType>): unknown

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
interactionAutocompleteInteraction <CacheType>The interaction that triggered the autocomplete.

Returns

unknown

Inherited from

Command.autocompleteRun

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1040


chatInputRun()

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

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 <CacheType>
contextChatInputCommandContext

Returns

Promise<void>

Overrides

Command.chatInputRun

Source

projects/plugins/packages/subcommands/src/lib/Subcommand.ts:350


contextMenuRun()?

optional contextMenuRun(interaction: ContextMenuCommandInteraction <CacheType>, context: ContextMenuCommandContext): unknown

Executes the context menu's logic.

Parameters

ParameterTypeDescription
interactionContextMenuCommandInteraction <CacheType>The interaction that triggered the command.
contextContextMenuCommandContextThe context menu command run context.

Returns

unknown

Inherited from

Command.contextMenuRun

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1027


messagePreParse()

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

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

Parameters

ParameterTypeDescription
messageMessage<boolean>The 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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:981


messageRun()

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

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<boolean>
argsPreParseReturn
contextMessageCommandContext

Returns

Promise<void>

Overrides

Command.messageRun

Source

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


onLoad()

onLoad(): void

Returns

void

Overrides

Command.onLoad

Source

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


onUnload()

onUnload(): unknown

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

Source

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


parseConstructorPreConditions()

protected parseConstructorPreConditions(options: CommandOptions): void

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

Inherited from

Command.parseConstructorPreConditions

Since

2.0.0

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1075


parseConstructorPreConditionsCooldown()

protected parseConstructorPreConditionsCooldown(options: CommandOptions): void

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1104


parseConstructorPreConditionsNsfw()

protected parseConstructorPreConditionsNsfw(options: CommandOptions): void

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1080


parseConstructorPreConditionsRequiredClientPermissions()

protected parseConstructorPreConditionsRequiredClientPermissions(options: CommandOptions): void

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1092


parseConstructorPreConditionsRequiredUserPermissions()

protected parseConstructorPreConditionsRequiredUserPermissions(options: CommandOptions): void

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1098


parseConstructorPreConditionsRunIn()

protected parseConstructorPreConditionsRunIn(options: CommandOptions): void

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1086


registerApplicationCommands()?

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

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

Parameters

ParameterTypeDescription
registryApplicationCommandRegistryThis command's registry

Returns

Awaitable<void>

Inherited from

Command.registerApplicationCommands

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1049


reload()

reload(): Promise<void>

Returns

Promise<void>

Inherited from

Command.reload

Source

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


resolveConstructorPreConditionsRunType()

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

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1110


supportsAutocompleteInteractions()

supportsAutocompleteInteractions(): this is AutocompleteCommand

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1065


supportsChatInputCommands()

supportsChatInputCommands(): this is ChatInputCommand

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

Source

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


supportsContextMenuCommands()

supportsContextMenuCommands(): this is ContextMenuCommand

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

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1061


supportsMessageCommands()

supportsMessageCommands(): boolean

Whether this command has message-based subcommands or not

Returns

boolean

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

Overrides

Command.supportsMessageCommands

Source

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


toJSON()

toJSON(): CommandJSON

Defines the JSON.stringify behavior of the command.

Returns

CommandJSON

Inherited from

Command.toJSON

Source

node_modules/@sapphire/framework/dist/esm/index.d.mts:1044


unload()

unload(): Promise<void>

Unloads and disables the piece.

Returns

Promise<void>

Inherited from

Command.unload

Source

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


runInTypeIsSpecificsObject()

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

Parameters

ParameterType
typesCommandRunInUnion | CommandSpecificRunIn

Returns

types is CommandSpecificRunIn

Inherited from

Command.runInTypeIsSpecificsObject

Source

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