Skip to content
This repository has been archived by the owner on Aug 28, 2020. It is now read-only.

Latest commit

 

History

History
25 lines (16 loc) · 1.36 KB

CommandsCustomResolvers.md

File metadata and controls

25 lines (16 loc) · 1.36 KB

This feature is implemented in Klasa 0.5.0, check the PR that implemented it here.

Custom Resolvers

Custom resolvers allow developers to set up custom types for each command, they are highly customizable and can hold its own logic and type name. This is possible thanks to the {@link Command.createCustomResolver} method.

Creating a custom Command Resolver

A custom resolver is usually created in the command constructor and its usage is identical to {@link ArgResolver} methods:

this.createCustomResolver('key', (arg, possible, message, params) => {
	// Logic
});

Where the first parameter is the name of the custom type, and the second is a function that takes arg (string), possible ({@link Possible}), message ({@link KlasaMessage}) and optionally, params (any[], remember parameters are parsed arguments).

Then in your usage, you can use the type key, it'll be recognized as a local resolver that your command is able to use. Check a live example here. You can also check the tutorial {@tutorial CreatingCustomArguments} for further information.

Further Reading:

  • {@tutorial CommandsArguments}
  • {@tutorial CommandsSubcommands}
  • {@tutorial CommandsCustomResponses}