Skip to main content

Class: Command<PreParseReturn, Options>

Defined in: projects/framework/src/lib/structures/Command.ts:36

Extends​

  • AliasPiece<Options, "commands">

Type Parameters​

Type ParameterDefault type
PreParseReturnArgs
Options extends OptionsOptions

Constructors​

Constructor​

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

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

Parameters​

ParameterTypeDescription
contextLoaderContextThe context.
optionsOptionsOptional Command settings.

Returns​

Command<PreParseReturn, Options>

Since​

1.0.0

Overrides​

AliasPiece<Options, 'commands'>.constructor

Properties​

applicationCommandRegistry​

readonly applicationCommandRegistry: ApplicationCommandRegistry

Defined in: projects/framework/src/lib/structures/Command.ts:93

The application command registry associated with this command.

Since​

3.0.0


description​

description: string

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

A basic summary about the command

Since​

1.0.0


detailedDescription​

detailedDescription: DetailedDescriptionCommand

Defined in: projects/framework/src/lib/structures/Command.ts:61

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

Since​

1.0.0


fullCategory​

readonly fullCategory: readonly string[]

Defined in: projects/framework/src/lib/structures/Command.ts:74

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


preconditions​

preconditions: PreconditionContainerArray

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

The preconditions to be run.

Since​

1.0.0


rawName​

rawName: string

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

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.


strategy​

strategy: IUnorderedStrategy

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

The strategy to use for the lexer.

Since​

1.0.0


typing​

typing: boolean

Defined in: projects/framework/src/lib/structures/Command.ts:87

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

Accessors​

category​

Get Signature​

get category(): null | string

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

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


parentCategory​

Get Signature​

get parentCategory(): null | string

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

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


subCategory​

Get Signature​

get subCategory(): null | string

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

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

Methods​

autocompleteRun()?​

optional autocompleteRun(interaction: AutocompleteInteraction): unknown

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

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
interactionAutocompleteInteractionThe interaction that triggered the autocomplete.

Returns​

unknown


chatInputRun()?​

optional chatInputRun(interaction: ChatInputCommandInteraction, context: ChatInputCommandContext): unknown

Defined in: projects/framework/src/lib/structures/Command.ts:208

Executes the application command's logic.

Parameters​

ParameterTypeDescription
interactionChatInputCommandInteractionThe interaction that triggered the command.
contextChatInputCommandContextThe chat input command run context.

Returns​

unknown


contextMenuRun()?​

optional contextMenuRun(interaction: ContextMenuCommandInteraction, context: ContextMenuCommandContext): unknown

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

Executes the context menu's logic.

Parameters​

ParameterTypeDescription
interactionContextMenuCommandInteractionThe interaction that triggered the command.
contextContextMenuCommandContextThe context menu command run context.

Returns​

unknown


messagePreParse()​

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

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

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

Parameters​

ParameterTypeDescription
messageMessageThe message that triggered the command.
parametersstringThe raw parameters as a single string.
contextMessageCommandContextThe command-context used in this execution.

Returns​

Awaitable<PreParseReturn>


messageRun()?​

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

Defined in: projects/framework/src/lib/structures/Command.ts:201

Executes the message command's logic.

Parameters​

ParameterTypeDescription
messageMessageThe 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


parseConstructorPreConditions()​

protected parseConstructorPreConditions(options: CommandOptions): void

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

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


parseConstructorPreConditionsCooldown()​

protected parseConstructorPreConditionsCooldown(options: CommandOptions): void

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

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


parseConstructorPreConditionsNsfw()​

protected parseConstructorPreConditionsNsfw(options: CommandOptions): void

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

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

Parameters​

ParameterTypeDescription
optionsCommandOptionsThe command options given from the constructor.

Returns​

void


parseConstructorPreConditionsRequiredClientPermissions()​

protected parseConstructorPreConditionsRequiredClientPermissions(options: CommandOptions): void

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

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


parseConstructorPreConditionsRequiredUserPermissions()​

protected parseConstructorPreConditionsRequiredUserPermissions(options: CommandOptions): void

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

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


parseConstructorPreConditionsRunIn()​

protected parseConstructorPreConditionsRunIn(options: CommandOptions): void

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

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


registerApplicationCommands()?​

optional registerApplicationCommands(registry: ApplicationCommandRegistry): Awaitable<void>

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

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

Parameters​

ParameterTypeDescription
registryApplicationCommandRegistryThis command's registry

Returns​

Awaitable<void>


reload()​

reload(): Promise<void>

Defined in: projects/framework/src/lib/structures/Command.ts:277

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

Returns​

Promise<void>

Overrides​

AliasPiece.reload


resolveConstructorPreConditionsRunType()​

protected resolveConstructorPreConditionsRunType(types: CommandRunInUnion): null | readonly ChannelType[]

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

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.


supportsAutocompleteInteractions()​

supportsAutocompleteInteractions(): this is AutocompleteCommand

Defined in: projects/framework/src/lib/structures/Command.ts:273

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

Returns​

this is AutocompleteCommand


supportsChatInputCommands()​

supportsChatInputCommands(): this is ChatInputCommand

Defined in: projects/framework/src/lib/structures/Command.ts:259

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

Returns​

this is ChatInputCommand


supportsContextMenuCommands()​

supportsContextMenuCommands(): this is ContextMenuCommand

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

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

Returns​

this is ContextMenuCommand


supportsMessageCommands()​

supportsMessageCommands(): this is MessageCommand

Defined in: projects/framework/src/lib/structures/Command.ts:252

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

Returns​

this is MessageCommand


toJSON()​

toJSON(): CommandJSON

Defined in: projects/framework/src/lib/structures/Command.ts:234

Defines the JSON.stringify behavior of the command.

Returns​

CommandJSON

Overrides​

AliasPiece.toJSON


runInTypeIsSpecificsObject()​

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

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

Parameters​

ParameterType
typesCommandRunInUnion | CommandSpecificRunIn

Returns​

types is CommandSpecificRunIn