Skip to main content

Class: Command<PreParseReturn, O>

Type parameters

NameType
PreParseReturnArgs
Oextends Options = Options

Hierarchy

Constructors

constructor

Protected new Command<PreParseReturn, O>(context, options?)

since 1.0.0

Type parameters

NameType
PreParseReturnArgs
Oextends CommandOptions<O> = CommandOptions

Parameters

NameTypeDescription
contextPieceContextThe context.
optionsOOptional Command settings.

Overrides

AliasPiece.constructor

Defined in

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

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


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


chatInputCommandOptions

Readonly Private chatInputCommandOptions: CommandChatInputRegisterShortcut

Options used to easily register chat input commands

since 3.0.0

Defined in

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


description

description: string

A basic summary about the command

since 1.0.0

Defined in

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


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


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


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


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


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


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

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


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


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

Methods

autocompleteRun

Optional 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:201


chatInputRun

Optional chatInputRun(interaction, context): unknown

Executes the application command's logic.

Parameters

NameTypeDescription
interactionCommandInteraction<CacheType>The interaction that triggered the command.
contextChatInputCommandContext-

Returns

unknown

Defined in

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


contextMenuRun

Optional contextMenuRun(interaction, context): unknown

Executes the context menu's logic.

Parameters

NameTypeDescription
interactionContextMenuInteraction<CacheType>The interaction that triggered the command.
contextContextMenuCommandContext-

Returns

unknown

Defined in

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


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


messageRun

Optional 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:175


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


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


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


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


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


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


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


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


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


supportsAutocompleteInteractions

supportsAutocompleteInteractions(): this is AutocompleteCommand

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

Returns

this is AutocompleteCommand

Defined in

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


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


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


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


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


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