Resolver

Resolver class to extend for creating Command argument resolvers. Custom Resolvers must implement the validate() and resolve() methods

Constructor

new Resolver(client: Client, name: string, aliases: string)

Parameters:
Name Type Attributes Description
client
Client

YAMDBF Client instance

name
string

Resolver type name. This is the type name used when specifying types in resolve and expect
Note: This is not passed by the ResolverLoader, so pass it to super() yourself when creating custom Resolvers

aliases
string
<repeatable>

Alternative names the Resolver can be identified by

Source:

Properties

.aliases: string[]

Additional identifier strings

Type:
string[]
Source:

.name: string

Name that servers as an identifier for the resolver

Type:
string
Source:

Methods

(abstract) .resolve(message: Message, command: Command, name: string, value: string) → Promise<any>

Method to implement that should accept a string and return a resolved value of the type the resolver is meant to resolve.

This method can and should throw errors when invalid input is given. These errors will be sent to Discord as argument errors when using the resolve middleware. Refer to the base Resolver error strings for examples on what these errors should look like if you're trying to keep things in-line with YAMDBF

Can be async

Parameters:
Name Type Description
message
Message

Discord.js Message instance

command
Command

Instance of the Command being called

name
string

Argument name

value
string

Argument value

Source:
Returns:
Promise<any>

(abstract) .resolveRaw(value: string, context?: Partial<Message>) → Promise<any>

Method recommended to be implemented for resolving data without side-effects. Where resolve() should throw errors which will be sent to Discord when a value cannot be resolved, this method should simply return undefined.

All base resolvers will implement this method with this signature so that they can be accessed for personal use via <Client>.resolvers.get('resolver name or alias').

Some resolvers require additional context in the form of a partial Message object in order to be able to resolve their data type from the given input (like needing a guild from the message to be able to resolve a GuildMember via the Member resolver). It's safest to assume that all base resolvers will want this context reference as only a small handful do not (specifically String, Number, Duration, Command, and CommandGroup). In the case of your own custom resolvers, you should know what needs context and what doesn't, so you can get away with passing as needed there.

In cases where a full Message object is unavailable but context is known, if you have a Guild instance, for example, you can simply pass it like

let resolved = <Resolver>.resolveRaw(value, { guild });

This is fine for all base resolvers, as the most any of them expect from the context is for it to contain a guild field with a Guild instance, and they will throw an error if the context they require is missing.

Can be async

Parameters:
Name Type Attributes Description
value
string

String value to resolve data from

context
Partial<Message>
<optional>

Partial Discord.js Message object

Source:
Returns:
Promise<any>

(abstract) .validate(value: any) → Promise<boolean>

Method to implement that should return whether or not the given value matches the type the resolver is meant to resolve.

Can be async

Parameters:
Name Type Description
value
any

Value to validate

Source:
Returns:
Promise<boolean>