Skip to main content

Class: ExtendedArgument<K, T>

deprecated ExtendedArgument is deprecated and will be removed in v3.0.0.

Use Argument instead, and abstract the resolving of the argument data to an external resolver.

The extended argument class. This class is abstract and is to be extended by subclasses which will implement the {@link ExtendedArgument#handle} method. Much like the Argument class, this class handles parsing user-specified command arguments into typed command parameters. However, this class can be used to expand upon an existing argument in order to process its transformed value rather than just the argument string.

example

// TypeScript:
import { ApplyOptions } from '@sapphire/decorators';
import { ExtendedArgument, ExtendedArgumentContext, ExtendedArgumentOptions } from '@sapphire/framework';
import type { Channel, TextChannel } from 'discord.js';

// Just like with `Argument`, you can use `export default` or `export =` too.
(at)ApplyOptions<ExtendedArgumentOptions>({
name: 'textChannel',
baseArgument: 'channel'
})
export class TextChannelArgument extends ExtendedArgument<'channel', TextChannel> {
public handle(parsed: Channel, { argument }: ExtendedArgumentContext): Argument.Result<TextChannel> {
return parsed.type === 'text'
? this.ok(parsed as TextChannel)
: this.error({ identifier: 'ArgumentTextChannelInvalidTextChannel', message: 'The argument did not resolve to a text channel.' });
}
}

example

// JavaScript:
const { ExtendedArgument } = require('@sapphire/framework');

module.exports = class TextChannelArgument extends ExtendedArgument {
constructor(context) {
super(context, { name: 'textChannel', baseArgument: 'channel' });
}

handle(parsed, { argument }) {
return parsed.type === 'text'
? this.ok(parsed)
: this.error({ identifier: 'ArgumentTextChannelInvalidTextChannel', message: 'The argument did not resolve to a text channel' });
}
}

Type parameters

NameType
Kextends keyof ArgType
TT

Hierarchy

Constructors

constructor

โ€ข new ExtendedArgument<K, T>(context, options)

deprecated ExtendedArgument is deprecated and will be removed in v3.0.0.

Type parameters

NameType
Kextends keyof ArgType
TT

Parameters

NameType
contextPieceContext
optionsExtendedArgumentOptions<K>

Overrides

Argument.constructor

Defined in

projects/framework/src/lib/structures/ExtendedArgument.ts:61

Properties

aliases

โ€ข aliases: readonly string[]

The aliases for the piece.

Inherited from

Argument.aliases

Defined in

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


baseArgument

โ€ข baseArgument: K

Defined in

projects/framework/src/lib/structures/ExtendedArgument.ts:56


enabled

โ€ข enabled: boolean

Whether or not the piece is enabled.

Inherited from

Argument.enabled

Defined in

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


location

โ€ข Readonly location: PieceLocation

The location metadata for the piece's file.

Inherited from

Argument.location

Defined in

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


name

โ€ข Readonly name: string

The name of the piece.

Inherited from

Argument.name

Defined in

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


options

โ€ข Readonly options: ArgumentOptions

The raw options passed to this Piece

Inherited from

Argument.options

Defined in

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


store

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

The store that contains the piece.

Inherited from

Argument.store

Defined in

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

Accessors

base

โ€ข get base(): IArgument<ArgType[K]>

Represents the underlying argument that transforms the raw argument into the value used to compute the extended argument's value.

deprecated ExtendedArgument is deprecated and will be removed in v3.0.0.

Returns

IArgument<ArgType[K]>

Defined in

projects/framework/src/lib/structures/ExtendedArgument.ts:71


container

โ€ข get container(): Container

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

see container

Returns

Container

Inherited from

Argument.container

Defined in

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

Methods

error

โ–ธ error(options): Result<T>

Constructs an ArgumentError with a custom type.

Parameters

NameType
optionsOmit<Options<T>, "argument">

Returns

Result<T>

Inherited from

Argument.error

Defined in

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


handle

โ–ธ Abstract handle(parsed, context): Result<T>

deprecated ExtendedArgument is deprecated and will be removed in v3.0.0.

Parameters

NameType
parsedArgType[K]
contextExtendedArgumentContext

Returns

Result<T>

Defined in

projects/framework/src/lib/structures/ExtendedArgument.ts:89


ok

โ–ธ ok(value): Result<T>

Wraps a value into a successful value.

Parameters

NameTypeDescription
valueTThe value to wrap.

Returns

Result<T>

Inherited from

Argument.ok

Defined in

projects/framework/src/lib/structures/Argument.ts:97


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

Argument.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

Argument.onUnload

Defined in

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


reload

โ–ธ reload(): Promise<void>

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

Returns

Promise<void>

Inherited from

Argument.reload

Defined in

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


run

โ–ธ run(parameter, context): AsyncResult<T>

deprecated ExtendedArgument is deprecated and will be removed in v3.0.0.

Parameters

NameType
parameterstring
contextContext<T>

Returns

AsyncResult<T>

Overrides

Argument.run

Defined in

projects/framework/src/lib/structures/ExtendedArgument.ts:78


toJSON

โ–ธ toJSON(): AliasPieceJSON

Defines the JSON.stringify behavior of this alias piece.

Returns

AliasPieceJSON

Inherited from

Argument.toJSON

Defined in

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


unload

โ–ธ unload(): Promise<void>

Unloads and disables the piece.

Returns

Promise<void>

Inherited from

Argument.unload

Defined in

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