Command

Command class to extend to create commands users can execute

Constructor

(abstract) new Command(info: CommandInfo)

Parameters:
Name Type Description
info
CommandInfo

Object containing required command properties

Source:

Properties

.aliases: string[]

Aliases the command can be called by other than its name

Type:
string[]
Source:

.argOpts: ArgOpts

Options for how arguments should be parsed.
See: ArgOpts

Type:
ArgOpts
Source:

.callerPermissions: PermissionResolvable[]

Array of permissions required by the command caller to be able to execute the command in the guild the command is called in.

If any permissions are provided the command's guildOnly property will be automatically overridden to true

Type:
PermissionResolvable[]
Source:

.client: Client

YAMDBF Client instance

Type:
Client
Source:

.clientPermissions: PermissionResolvable[]

Array of permissions required by the client to be able to execute the command in the guild the command is called in.

If any permissions are provided the command's guildOnly property will be automatically overridden to true

Type:
PermissionResolvable[]
Source:

.desc: string

A brief description of the command, displayed in the commands list via the Help command

Type:
string
Source:

.disabled: boolean

Whether or not this command is disabled

Type:
boolean
Source:

.external: boolean

Whether or not this command was registered via CommandRegistry#registerExternal by some means other than the command loader like a Plugin

Type:
boolean
Source:

.group: string

The command group that the command belongs to. Allows commands to be grouped for disabling. The group 'base' cannot be disabled.

Type:
string
Source:

.guildOnly: boolean

Whether or not a command can only be used within a guild text channel

Type:
boolean
Source:

.hidden: boolean

Whether or not the command is to be hidden from the commands list via the default help command

Type:
boolean
Source:

.info: string

Extra information about the command to be displayed by the Help command when help <command> is called

Type:
string
Source:

.lock: CommandLock

The CommmandLock this command uses. Must be assigned manually if locking functionality is desired

Type:
CommandLock
Source:

.lockTimeout: number

Time until command locks will be cancelled if a command does not finish in time

Type:
number
Source:

.name: string

The name of the command, used by the dispatcher to determine the command being executed

Type:
string
Source:

.ownerOnly: boolean

Whether or not the command can be used only by the client/bot owner(s).
See: Client#config.owner

Type:
boolean
Source:

.ratelimit: string

The ratelimit for this command per user

Type:
string
Source:

.roles: string[]

Array of specific Role names required to use the command. If the command caller has any (even just one) of the roles in the array, they will be able to use the command.

If any roles are provided the command's guildOnly property will be automatically set to true

Note: This is far inferior to Command#callerPermissions, using the base limit command's role-limiting system, or really even a custom-engineered solution to control who can use a command. Forcing servers to create Roles with specific names makes your bot that much less configurable on a per-guild basis, and configurability is what YAMDBF is all about. But, for the sake of simplicity, this is available

Type:
string[]
Source:

.usage: string

An example of command usage. The token <prefix> will be replaced by the guild-specific command prefix in the Help command when help <command> is called

Type:
string
Source:

Methods

(abstract) .action(message: Message, args: any[]) → any

Action to be executed when the command is called. The following parameters are what command actions will be passed by the CommandDispatcher whenever a command is called. Be sure to receive these in proper order when writing new commands

Parameters:
Name Type Description
message
Message

Discord.js message object

args
any[]

An array containing the args parsed from the command calling message.
Will contain strings unless middleware is used to transform the args

Source:
Returns:
any

.disable() → void

Disable this command if it is enabled

Source:
Returns:
void

.enable() → void

Enable this command if it is disabled

Source:
Returns:
void

(abstract) .init() → Promise<void>

Can be included in a command to initlialize any resources a command needs at runtime that require things that are not available within a command's constructor like the client instance or client/guild storages.

Will be called after all commands are loaded (including those from any loaded plugins) and after all base framework storages (client and guild) are ready for use.

Note: Can be async if needed

Source:
Returns:
Promise<void>

(protected) .respond(message: Message, response: string, options?: RespondOptions) → Promise<Message | Message[]|undefined>

Send provided response to the provided message's channel, leveraging compact mode mechanics if enabled

Parameters:
Name Type Attributes Description
message
Message

Discord.js Message object

response
string

String to send

options
RespondOptions
<optional>

Optional options for the response

Source:
Returns:
Promise<Message | Message[]|undefined>

.use(func: MiddlewareFunction)Command

Adds a middleware function to be used when the command is called to make modifications to args, determine if the command can be run, or anything else you want to do whenever this command is called.

See MiddlewareFunction for information on how a middleware function should be represented

Usage example:

<Client>.use((message, args) => [message, args.map(a => a.toUpperCase())]);

This will add a middleware function to this command that will attempt to transform all args to uppercase. This will of course fail if any of the args are not a string.

Note: Middleware functions should only be added to a command one time each and thus should not be added within any sort of event or loop. Multiple separate middleware functions can be added to the via multiple separate calls to this method

Parameters:
Name Type Description
func
MiddlewareFunction

The middleware function to use

Source:
Returns:
Command