Skip to main content

Class: Command<T, O>

Type parameters

NameType
TArgs
Oextends Options = Options

Hierarchy

Constructors

constructor

โ€ข Protected new Command<T, O>(context, options?)

since 1.0.0

Type parameters

NameType
TArgs
Oextends CommandOptions<O> = CommandOptions

Parameters

NameTypeDescription
contextPieceContextThe context.
optionsCommandOptionsOptional Command settings.

Overrides

AliasPiece.constructor

Defined in

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

Properties

aliases

โ€ข aliases: readonly string[]

The aliases for the piece.

Inherited from

AliasPiece.aliases

Defined in

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


description

โ€ข description: string

A basic summary about the command

since 1.0.0

Defined in

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


detailedDescription

โ€ข detailedDescription: string

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

since 1.0.0

Defined in

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


enabled

โ€ข enabled: boolean

Whether or not the piece is enabled.

Inherited from

AliasPiece.enabled

Defined in

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


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 for how you setup 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

Defined in

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


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:57


location

โ€ข Readonly location: PieceLocation

The location metadata for the piece's file.

Inherited from

AliasPiece.location

Defined in

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


name

โ€ข Readonly name: string

The name of the piece.

Inherited from

AliasPiece.name

Defined in

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


options

โ€ข Readonly options: O

The raw options passed to this Piece

Inherited from

AliasPiece.options

Defined in

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


preconditions

โ€ข preconditions: PreconditionContainerArray

The preconditions to be run.

since 1.0.0

Defined in

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


store

โ€ข Readonly store: Store<Piece<PieceOptions>>

The store that contains the piece.

Inherited from

AliasPiece.store

Defined in

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


strategy

โ€ข strategy: UnorderedStrategy

The strategy to use for the lexer.

since 1.0.0

Defined in

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


typing

โ€ข typing: boolean

If {@link 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:50

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 {@link Command.Options.fullCategory} to override the built-in category resolution.

Returns

null | string

Defined in

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


container

โ€ข get container(): Container

A reference to the {@link Container} object for ease of use.

see container

Returns

Container

Inherited from

AliasPiece.container

Defined in

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


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 {@link Command.Options.fullCategory} to override the built-in category resolution.

Returns

null | string

Defined in

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


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 {@link Command.Options.fullCategory} to override the built-in category resolution.

Returns

null | string

Defined in

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

Methods

messageRun

โ–ธ Abstract messageRun(message, args, context): unknown

Executes the command's logic for a message.

Parameters

NameTypeDescription
messageMessage<boolean>The message that triggered the command.
argsTThe value returned by Command.preParse, by default an instance of Args.
contextCommandContext-

Returns

unknown

Defined in

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


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/index.d.ts:462


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/index.d.ts:467


parseConstructorPreConditions

โ–ธ Protected parseConstructorPreConditions(options): void

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

since 2.0.0

Parameters

NameTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns

void

Defined in

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


parseConstructorPreConditionsCooldown

โ–ธ Protected parseConstructorPreConditionsCooldown(options): void

Appends the Cooldown precondition when {@link Command.Options.cooldownLimit} and {@link 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:233


parseConstructorPreConditionsNsfw

โ–ธ Protected parseConstructorPreConditionsNsfw(options): void

Appends the NSFW precondition if {@link 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:189


parseConstructorPreConditionsRequiredClientPermissions

โ–ธ Protected parseConstructorPreConditionsRequiredClientPermissions(options): void

Appends the ClientPermissions precondition when {@link 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:209


parseConstructorPreConditionsRequiredUserPermissions

โ–ธ Protected parseConstructorPreConditionsRequiredUserPermissions(options): void

Appends the UserPermissions precondition when {@link 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:221


parseConstructorPreConditionsRunIn

โ–ธ Protected parseConstructorPreConditionsRunIn(options): void

Appends the DMOnly, GuildOnly, NewsOnly, and TextOnly preconditions based on the values passed in {@link Command.Options.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

Defined in

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


preParse

โ–ธ preParse(message, parameters, context): Awaitable<T>

The 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.
contextCommandContextThe command-context used in this execution.

Returns

Awaitable<T>

Defined in

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


reload

โ–ธ reload(): Promise<void>

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

Returns

Promise<void>

Inherited from

AliasPiece.reload

Defined in

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


resolveConstructorPreConditionsRunType

โ–ธ Private resolveConstructorPreConditionsRunType(runIn): null | PreconditionContainerArray | CommandPreConditions

Parameters

NameType
runInundefined | null | CommandOptionsRunType | CommandOptionsRunTypeEnum | readonly (CommandOptionsRunType | CommandOptionsRunTypeEnum)[]

Returns

null | PreconditionContainerArray | CommandPreConditions

Defined in

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


run

โ–ธ Optional run(message, args, context): unknown

Executes the command's logic.

deprecated Use messageRun instead.

Parameters

NameTypeDescription
messageMessage<boolean>The message that triggered the command.
argsTThe value returned by Command.preParse, by default an instance of Args.
contextCommandContext-

Returns

unknown

Defined in

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


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:160


unload

โ–ธ unload(): Promise<void>

Unloads and disables the piece.

Returns

Promise<void>

Inherited from

AliasPiece.unload

Defined in

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