Skip to main content

Class: Subcommand<PreParseReturn, O>

@sapphire/plugin-subcommands.Subcommand

Type parameters

NameType
PreParseReturnextends Args = Args
Oextends Options = Options

Hierarchy

  • Command<PreParseReturn, O>

    Subcommand

Constructors

constructor

new Subcommand<PreParseReturn, O>(context, options)

Type parameters

NameType
PreParseReturnextends Args<PreParseReturn> = Args
Oextends SubcommandOptions<O> = SubcommandOptions

Parameters

NameType
contextPieceContext
optionsO

Overrides

Command<PreParseReturn, O\>.constructor

Defined in

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

Properties

aliases

aliases: readonly string[]

The aliases for the piece.

Inherited from

Command.aliases

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:687


applicationCommandRegistry

Readonly applicationCommandRegistry: ApplicationCommandRegistry

The application command registry associated with this command.

Since

3.0.0

Inherited from

Command.applicationCommandRegistry

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2146


caseInsensitiveSubcommands

caseInsensitiveSubcommands: boolean = false

Defined in

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


description

description: string

A basic summary about the command

Since

1.0.0

Inherited from

Command.description

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2111


detailedDescription

detailedDescription: DetailedDescriptionCommand

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

Since

1.0.0

Inherited from

Command.detailedDescription

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2121


enabled

enabled: boolean

Whether or not the piece is enabled.

Inherited from

Command.enabled

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:450


fullCategory

Readonly fullCategory: readonly string[]

The full category for the command. Either an array of strings that denote every (sub)folder the command is in, or null if it could not be resolved automatically.

If this is null with how you set up your code then you can overwrite how the fullCategory is resolved by extending this class and overwriting the assignment in the constructor.

Since

2.0.0

Inherited from

Command.fullCategory

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2130


lexer

Private lexer: Lexer

The lexer to be used for command parsing

Since

1.0.0

Inherited from

Command.lexer

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2152


location

Readonly location: PieceLocation

The location metadata for the piece's file.

Inherited from

Command.location

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:442


name

Readonly name: string

The name of the piece.

Inherited from

Command.name

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:446


options

Readonly options: O

The raw options passed to this Piece

Inherited from

Command.options

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:454


parsedSubcommandMappings

parsedSubcommandMappings: SubcommandMappingArray

Defined in

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


preconditions

preconditions: PreconditionContainerArray

The preconditions to be run.

Since

1.0.0

Inherited from

Command.preconditions

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2116


store

store: CommandStore

The CommandStore that contains this Command.

Inherited from

Command.store

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2106


strategy

strategy: IUnorderedStrategy

The strategy to use for the lexer.

Since

1.0.0

Inherited from

Command.strategy

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2135


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

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2141

Accessors

category

get category(): null | string

The main category for the command, if any.

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

Note

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

Returns

null | string

Inherited from

Command.category

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2174


container

get container(): Container

A reference to the Container object for ease of use.

See

container

Returns

Container

Inherited from

Command.container

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:460


parentCategory

get parentCategory(): null | string

The parent category for the command.

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

Note

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

Returns

null | string

Inherited from

Command.parentCategory

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2192


subCategory

get subCategory(): null | string

The sub-category for the command, if any.

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

Note

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

Returns

null | string

Inherited from

Command.subCategory

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2183

Methods

#findSubcommand

Private #findSubcommand(mappings, expectedName): { defaultMatch: false = false; mapping: SubcommandMappingMethod } | { defaultMatch: true = true; mapping: null | SubcommandMappingMethod = foundDefault }

Parameters

NameType
mappingsSubcommandMappingMethod[]
expectedNamestring

Returns

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

Defined in

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


#handleChatInputInteractionRun

Private #handleChatInputInteractionRun(interaction, context, subcommand): Promise<void>

Parameters

NameType
interactionInteraction<CacheType>
contextChatInputCommandContext
subcommandSubcommandMappingMethod

Returns

Promise<void>

Defined in

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


#handleMessageRun

Private #handleMessageRun(message, args, context, subcommand): Promise<void>

Parameters

NameType
messageMessage<boolean>
argsArgs
contextMessageCommandContext
subcommandSubcommandMappingMethod

Returns

Promise<void>

Defined in

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


#supportsCommandType

Private #supportsCommandType(commandType): boolean

Parameters

NameType
commandType"chatInputRun" | "messageRun"

Returns

boolean

Defined in

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


autocompleteRun

Optional autocompleteRun(interaction): 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

NameTypeDescription
interactionAutocompleteInteraction<CacheType>The interaction that triggered the autocomplete.

Returns

unknown

Inherited from

Command.autocompleteRun

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2224


chatInputRun

chatInputRun(interaction, context): Promise<void>

Parameters

NameType
interactionInteraction<CacheType>
contextChatInputCommandContext

Returns

Promise<void>

Overrides

Command.chatInputRun

Defined in

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


contextMenuRun

Optional contextMenuRun(interaction, context): unknown

Executes the context menu's logic.

Parameters

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

Returns

unknown

Inherited from

Command.contextMenuRun

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2211


messagePreParse

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

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

Parameters

NameTypeDescription
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

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2165


messageRun

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

Parameters

NameType
messageMessage<boolean>
argsPreParseReturn
contextMessageCommandContext

Returns

Promise<void>

Overrides

Command.messageRun

Defined in

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


onLoad

onLoad(): void

Returns

void

Overrides

Command.onLoad

Defined in

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


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

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:470


parseConstructorPreConditions

Protected parseConstructorPreConditions(options): void

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

Since

2.0.0

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Inherited from

Command.parseConstructorPreConditions

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2259


parseConstructorPreConditionsCooldown

Protected parseConstructorPreConditionsCooldown(options): void

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

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Inherited from

Command.parseConstructorPreConditionsCooldown

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2289


parseConstructorPreConditionsNsfw

Protected parseConstructorPreConditionsNsfw(options): void

Appends the NSFW precondition if nsfw is set to true.

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Inherited from

Command.parseConstructorPreConditionsNsfw

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2264


parseConstructorPreConditionsRequiredClientPermissions

Protected parseConstructorPreConditionsRequiredClientPermissions(options): void

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

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Inherited from

Command.parseConstructorPreConditionsRequiredClientPermissions

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2277


parseConstructorPreConditionsRequiredUserPermissions

Protected parseConstructorPreConditionsRequiredUserPermissions(options): void

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

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Inherited from

Command.parseConstructorPreConditionsRequiredUserPermissions

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2283


parseConstructorPreConditionsRunIn

Protected parseConstructorPreConditionsRunIn(options): void

Appends the DMOnly, GuildOnly, NewsOnly, and TextOnly preconditions based on the values passed in runIn, optimizing in specific cases (NewsOnly + TextOnly = GuildOnly; DMOnly + GuildOnly = null), defaulting to null, which doesn't add a precondition.

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Inherited from

Command.parseConstructorPreConditionsRunIn

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2271


registerApplicationCommands

Optional registerApplicationCommands(registry): Awaitable<void>

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

Parameters

NameTypeDescription
registryApplicationCommandRegistryThis command's registry

Returns

Awaitable<void>

Inherited from

Command.registerApplicationCommands

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2233


reload

reload(): Promise<void>

Returns

Promise<void>

Inherited from

Command.reload

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2250


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

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2249


supportsChatInputCommands

supportsChatInputCommands(): this is ChatInputCommand

Returns

this is ChatInputCommand

Overrides

Command.supportsChatInputCommands

Defined in

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


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

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2245


supportsMessageCommands

supportsMessageCommands(): boolean

Returns

boolean

Overrides

Command.supportsMessageCommands

Defined in

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


toJSON

toJSON(): CommandJSON

Defines the JSON.stringify behavior of the command.

Returns

CommandJSON

Inherited from

Command.toJSON

Defined in

node_modules/@sapphire/framework/dist/index.d.ts:2228


unload

unload(): Promise<void>

Unloads and disables the piece.

Returns

Promise<void>

Inherited from

Command.unload

Defined in

node_modules/@sapphire/pieces/dist/index.d.ts:474