Constructor
new Resolver(client: Client, name: string, aliases: string)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
client |
|
YAMDBF Client instance |
|
name |
|
Resolver type name. This is the type name used
when specifying types in |
|
aliases |
|
<repeatable> |
Alternative names the Resolver can be identified by |
Properties
.aliases: string[]
.name: string
Name that servers as an identifier for the resolver
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 |
|
Discord.js Message instance |
command |
|
Instance of the Command being called |
name |
|
Argument name |
value |
|
Argument value |
(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 value to resolve data from |
|
context |
|
<optional> |
Partial Discord.js Message object |
(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 |
|
Value to validate |