Skip to main content

Class: Command<PreParseReturn, Options>

The piece to be stored in AliasStore instances.

Type parameters

NameType
PreParseReturnArgs
Optionsextends Options = Options

Hierarchy

Constructors

constructor

new Command<PreParseReturn, Options>(context, options?): Command<PreParseReturn, Options>

Type parameters

NameType
PreParseReturnArgs
Optionsextends CommandOptions = CommandOptions

Parameters

NameTypeDescription
contextLoaderContextThe context.
optionsOptionsOptional Command settings.

Returns

Command<PreParseReturn, Options>

Since

1.0.0

Overrides

AliasPiece.constructor

Defined in

projects/framework/src/lib/structures/Command.ts:99

Properties

aliases

aliases: readonly string[]

The aliases for the piece.

Inherited from

AliasPiece.aliases

Defined in

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

Defined in

projects/framework/src/lib/structures/Command.ts:85


description

description: string

A basic summary about the command

Since

1.0.0

Defined in

projects/framework/src/lib/structures/Command.ts:41


detailedDescription

detailedDescription: DetailedDescriptionCommand

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

Since

1.0.0

Defined in

projects/framework/src/lib/structures/Command.ts:53


enabled

enabled: boolean

Whether or not the piece is enabled.

Inherited from

AliasPiece.enabled

Defined in

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

Defined in

projects/framework/src/lib/structures/Command.ts:66


lexer

Private lexer: Lexer

The lexer to be used for command parsing

Since

1.0.0

Defined in

projects/framework/src/lib/structures/Command.ts:92


location

Readonly location: PieceLocation

The location metadata for the piece's file.

Inherited from

AliasPiece.location

Defined in

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


name

Readonly name: string

The name of the piece.

Inherited from

AliasPiece.name

Defined in

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


options

Readonly options: Options

The raw options passed to this Piece

Inherited from

AliasPiece.options

Defined in

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


preconditions

preconditions: PreconditionContainerArray

The preconditions to be run.

Since

1.0.0

Defined in

projects/framework/src/lib/structures/Command.ts:47


store

Readonly store: CommandStore

The store that contains the piece.

Inherited from

AliasPiece.store

Defined in

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


strategy

strategy: IUnorderedStrategy

The strategy to use for the lexer.

Since

1.0.0

Defined in

projects/framework/src/lib/structures/Command.ts:72


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

Defined in

projects/framework/src/lib/structures/Command.ts:79

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.

Returns

null | string

Note

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

Defined in

projects/framework/src/lib/structures/Command.ts:156


container

get container(): Container

A reference to the Container object for ease of use.

Returns

Container

See

container

Inherited from

AliasPiece.container

Defined in

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.

Returns

null | string

Note

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

Defined in

projects/framework/src/lib/structures/Command.ts:180


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.

Returns

null | string

Note

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

Defined in

projects/framework/src/lib/structures/Command.ts:168

Methods

autocompleteRun

autocompleteRun(interaction): unknown

Executes the autocomplete logic.

tip

You may use this, or alternatively create an 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

Defined in

projects/framework/src/lib/structures/Command.ts:218


chatInputRun

chatInputRun(interaction, context): unknown

Executes the application command's logic.

Parameters

NameTypeDescription
interactionChatInputCommandInteraction<CacheType>The interaction that triggered the command.
contextChatInputCommandContextThe chat input command run context.

Returns

unknown

Defined in

projects/framework/src/lib/structures/Command.ts:197


contextMenuRun

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

Defined in

projects/framework/src/lib/structures/Command.ts:204


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>

Defined in

projects/framework/src/lib/structures/Command.ts:142


messageRun

messageRun(message, args, context): unknown

Executes the message command's logic.

Parameters

NameTypeDescription
messageMessage<boolean>The message that triggered the command.
argsPreParseReturnThe value returned by Command.messagePreParse, by default an instance of Args.
contextMessageCommandContextThe context in which the command was executed.

Returns

unknown

Defined in

projects/framework/src/lib/structures/Command.ts:190


onLoad

onLoad(): unknown

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

Returns

unknown

Inherited from

AliasPiece.onLoad

Defined in

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


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

AliasPiece.onUnload

Defined in

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


parseConstructorPreConditions

parseConstructorPreConditions(options): void

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

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Since

2.0.0

Defined in

projects/framework/src/lib/structures/Command.ts:349


parseConstructorPreConditionsCooldown

parseConstructorPreConditionsCooldown(options): void

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

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Defined in

projects/framework/src/lib/structures/Command.ts:397


parseConstructorPreConditionsNsfw

parseConstructorPreConditionsNsfw(options): void

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

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Defined in

projects/framework/src/lib/structures/Command.ts:361


parseConstructorPreConditionsRequiredClientPermissions

parseConstructorPreConditionsRequiredClientPermissions(options): void

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

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Defined in

projects/framework/src/lib/structures/Command.ts:379


parseConstructorPreConditionsRequiredUserPermissions

parseConstructorPreConditionsRequiredUserPermissions(options): void

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

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Defined in

projects/framework/src/lib/structures/Command.ts:388


parseConstructorPreConditionsRunIn

parseConstructorPreConditionsRunIn(options): void

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

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Defined in

projects/framework/src/lib/structures/Command.ts:370


registerApplicationCommands

registerApplicationCommands(registry): Awaitable<void>

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

Parameters

NameTypeDescription
registryApplicationCommandRegistryThis command's registry

Returns

Awaitable<void>

Defined in

projects/framework/src/lib/structures/Command.ts:236


reload

reload(): Promise<void>

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

Returns

Promise<void>

Overrides

AliasPiece.reload

Defined in

projects/framework/src/lib/structures/Command.ts:266


resolveConstructorPreConditionsRunType

resolveConstructorPreConditionsRunType(types): null | readonly ChannelType[]

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

Parameters

NameTypeDescription
typesCommandRunInUnionThe types to resolve.

Returns

null | readonly ChannelType[]

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

Defined in

projects/framework/src/lib/structures/Command.ts:413


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

Defined in

projects/framework/src/lib/structures/Command.ts:262


supportsChatInputCommands

supportsChatInputCommands(): this is ChatInputCommand

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

Returns

this is ChatInputCommand

Defined in

projects/framework/src/lib/structures/Command.ts:248


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

Defined in

projects/framework/src/lib/structures/Command.ts:255


supportsMessageCommands

supportsMessageCommands(): this is MessageCommand

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

Returns

this is MessageCommand

Defined in

projects/framework/src/lib/structures/Command.ts:241


toJSON

toJSON(): CommandJSON

Defines the JSON.stringify behavior of the command.

Returns

CommandJSON

Overrides

AliasPiece.toJSON

Defined in

projects/framework/src/lib/structures/Command.ts:223


unload

unload(): Promise<void>

Unloads and disables the piece.

Returns

Promise<void>

Inherited from

AliasPiece.unload

Defined in

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


runInTypeIsSpecificsObject

runInTypeIsSpecificsObject(types): types is CommandSpecificRunIn

Parameters

NameType
typesCommandRunInUnion | CommandSpecificRunIn

Returns

types is CommandSpecificRunIn

Defined in

projects/framework/src/lib/structures/Command.ts:460