Skip to main content

Class: Command<PreParseReturn, Options>

Extends​

  • AliasPiece<Options, "commands">

Type Parameters​

Type ParameterDefault type
PreParseReturnArgs
Options extends OptionsOptions

Constructors​

new Command()​

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

Parameters​

ParameterTypeDescription
contextLoaderContextThe context.
optionsOptionsOptional Command settings.

Returns​

Command<PreParseReturn, Options>

Since​

1.0.0

Overrides​

AliasPiece<Options, 'commands'>.constructor

Defined in​

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

Properties​

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


description​

description: string

A basic summary about the command

Since​

1.0.0

Defined in​

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


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


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


preconditions​

preconditions: PreconditionContainerArray

The preconditions to be run.

Since​

1.0.0

Defined in​

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


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.

Defined in​

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


strategy​

strategy: IUnorderedStrategy

The strategy to use for the lexer.

Since​

1.0.0

Defined in​

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


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

Accessors​

category​

Get Signature​

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

Defined in​

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


parentCategory​

Get Signature​

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

Defined in​

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


subCategory​

Get Signature​

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

Defined in​

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

Methods​

autocompleteRun()?​

optional autocompleteRun(interaction: AutocompleteInteraction<CacheType>): 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​

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

Returns​

unknown

Defined in​

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


chatInputRun()?​

optional chatInputRun(interaction: ChatInputCommandInteraction<CacheType>, context: ChatInputCommandContext): unknown

Executes the application command's logic.

Parameters​

ParameterTypeDescription
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:208


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

Defined in​

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


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>

Defined in​

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


messageRun()?​

optional messageRun(message: Message<boolean>, args: PreParseReturn, context: MessageCommandContext): unknown

Executes the message command's logic.

Parameters​

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


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

Since​

2.0.0

Defined in​

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


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

Defined in​

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


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

Defined in​

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


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

Defined in​

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


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

Defined in​

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


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

Defined in​

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


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>

Defined in​

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


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


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.

Defined in​

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


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


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


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


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


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


runInTypeIsSpecificsObject()​

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

Parameters​

ParameterType
typesCommandRunInUnion | CommandSpecificRunIn

Returns​

types is CommandSpecificRunIn

Defined in​

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