Command

Command

Represents an command framework command

Constructor

new Command(label, generator, optionsopt)

Register a command

Properties:
Name Type Attributes Description
aliases Array.<String>

An array of command aliases

argsRequired Boolean

If arguments are required or not

caseInsensitive Boolean

Whether the command label (and aliases) is case insensitive or not

cooldown Number

The cooldown between command usage in milliseconds

cooldownExclusions Object

A set of factors that limit where cooldowns are active

cooldownMessage function | String

A string or a function that returns a string to show when the command is on cooldown.

cooldownReturns Number

Number of times to return a message when the command is used during it's cooldown.

defaultSubcommandOptions Object

Default subcommand options.

deleteCommand Boolean

Whether to delete the user command message or not

description String

A short description of the command

dmOnly Boolean

Whether the command is prevented from being used in guilds or not

errorMessage function | String

A string or a function that returns a string to show if the execution of the command handler somehow fails. The function is passed the Message object as a parameter.

fullDescription String

A detailed description of the command

fullLabel String

The full command label

guildOnly Boolean

Whether the command is prevented from being used in Direct Messages or not

hidden Boolean

Whether or not the command is hidden from the default help command list.

hooks Object

A set of functions to be executed at different times throughout the command's processing

invalidUsageMessage function | String

A string or a function that returns a string to show when a command was improperly used.

label String

The command label

parentCommand Command <nullable>

If this command is also a subcommand, this will refer to its parent Command

permissionMessage function | String

A string or a function that returns a string to show when the user doesn't have permissions to use the command.

reactionButtons Object <nullable>

An array of objects specifying reaction buttons, or null if no reaction buttons.

reactionButtonTimeout Number

Time (in milliseconds) to wait before invalidating the command's reaction buttons

requirements Object

A set of factors that limit who can call the command

restartCooldown Boolean

Whether or not to restart a command's cooldown every time it's used

subcommands Object

Object mapping subcommand labels to Command objects

subcommandAliases Object

Object mapping subcommand aliases to their respective subcommand label

usage String

Details on how to call the command to show in the default help command

Source:
Parameters:
Name Type Attributes Default Description
label String

The command label

generator function | String | Array.<(function()|String)>

A response string, array of functions or strings, or function that generates a string or array of strings when called. If a function is passed, the function will be passed a Message object and an array of command arguments. The Message object will have an additional property prefix, which is the prefix used in the command. generator(msg, args)

options Object <optional>

Command options

Name Type Attributes Default Description
aliases Array.<String> <optional>

An array of command aliases

argsRequired Boolean <optional>
false

If arguments are required or not

caseInsensitive Boolean <optional>
false

Whether the command label (and aliases) is case insensitive or not

cooldown Number <optional>

The cooldown between command usage in milliseconds

cooldownExclusions Object <optional>
{}

A set of factors that limit where cooldowns are active

Name Type Attributes Description
channelIDs Array.<String> <optional>

An array of channel IDs representing channels that are not affected by cooldowns.

guildIDs Array.<String> <optional>

An array of guild IDs representing guilds that are not affected by cooldowns.

userIDs Array.<String> <optional>

An array of user IDs representing users that are not affected by cooldowns.

cooldownMessage function | String | Object <optional>

A string or createMessage() content object, or a function that returns either of those, to show when the command is on cooldown. The function is passed the Message object as a parameter.

option.cooldownReturns Number <optional>
0

Number of times to return a message when the command is used during it's cooldown. Once the cooldown expires this is reset. Set this to 0 to always return a message.

options.defaultSubcommandOptions Object <optional>
{}

Default subcommand options. This object takes the same options as a normal Command

options.deleteCommand Boolean <optional>
false

Whether to delete the user command message or not

options.description String <optional>
"No description"

A short description of the command to show in the default help command

options.dmOnly Boolean <optional>
false

Whether to prevent the command from being used in guilds or not

options.errorMessage function | String | Object <optional>

A string or createMessage() content object, or a function that returns either of those, to show if the execution of the command handler somehow fails. The function is passed the Message object as a parameter.

options.fullDescription String <optional>
"No full description"

A detailed description of the command to show in the default help command

options.guildOnly Boolean <optional>
false

Whether to prevent the command from being used in Direct Messages or not

options.hidden Boolean <optional>
false

Whether or not the command should be hidden from the default help command list.

options.hooks Object <optional>

A set of functions to be executed at different times throughout the command's processing

Name Type Attributes Description
postCheck function <optional>

A function that is executed after all checks have cleared, but before the command is executed. The function is passed the command message, arguments, and if command checks were passed as parameters.

postCommand function <optional>

A function that is executed after a response has been posted, and the command has finished processing. The function is passed the command message, arguments, and the response message (if applicable) as parameters.

postExecution function <optional>

A function that is executed after the command is executed, regardless of the final failed state of the command. The function is passed the command message, arguments, and if execution succeeded as parameters.

preCommand function <optional>

A function that is executed before any permission or cooldown checks is made. The function is passed the command message and arguments as parameters.

options.invalidUsageMessage function | String | Object <optional>

A string or createMessage() content object, or a function that returns either of those, to show when a command was improperly used. The function is passed the Message object as a parameter.

options.permissionMessage function | String | Object <optional>

A string or createMessage() content object, or a function that returns either of those, to show when the user doesn't have permissions to use the command. The function is passed the Message object as a parameter.

options.reactionButtons Array.<{emoji: String, type: String, response: (function()|String|Array.<(function()|String)>), filter: function()}> <optional>

An array of objects specifying reaction buttons emoji specifies the button emoji. Custom emojis should be in format emojiName:emojiID type specifies the type of the reaction button, either "edit" or "cancel" response specifies the content to edit the message to when the reaction button is pressed. This accepts the same arguments as the generator parameter of this function, but with an extra userID parameter for generator functions (function(msg, args, userID)) describing the user that made the reaction filter specifies a function (function(msg, emoji, userID)) that filters message reactions. If the function returns false, the reaction is not treated as a valid reaction button response

options.reactionButtonTimeout Number <optional>
60000

Time (in milliseconds) to wait before invalidating the command's reaction buttons

options.requirements Object <optional>

A set of factors that limit who can call the command

Name Type Attributes Description
custom function <optional>

A function that accepts a message and returns true if the command should be run

permissions function | Object <optional>

An object or a function that returns an object containing permission keys the user must match to use the command. The function is passed the Message object as a parameter. i.e.:

{
  "administrator": false,
  "manageMessages": true
}

In the above example, the user must not have administrator permissions, but must have manageMessages to use the command

roleIDs function | Array.<String> <optional>

An array or a function that returns an array of role IDs that would allow a user to use the command. The function is passed the Message object as a parameter.

roleNames function | Array.<String> <optional>

An array or a function that returns an array of role names that would allow a user to use the command. The function is passed the Message object as a parameter.

userIDs function | Array.<String> <optional>

An array or a function that returns an array of user IDs representing users that can call the command. The function is passed the Message object as a parameter.

option.restartCooldown Boolean <optional>
false

Whether or not to restart a command's cooldown every time it's used.

options.usage String <optional>

Details on how to call the command to show in the default help command

Methods

registerSubcommand(label, generator, optionsopt) → {Command}

Register a subcommand

Source:
Parameters:
Name Type Attributes Default Description
label String

The subcommand label

generator function | String | Array.<(function()|String)>

A response string, array of functions or strings, or function that generates a string or array of strings when called. If a function is passed, the function will be passed a Message object and an array of subcommand arguments. The Message object will have an additional property prefix, which is the prefix used in the subcommand. generator(msg, args)

options Object <optional>

Command options

Name Type Attributes Default Description
aliases Array.<String> <optional>

An array of command aliases

argsRequired Boolean <optional>
false

If arguments are required or not

caseInsensitive Boolean <optional>
false

Whether the command label (and aliases) is case insensitive or not

cooldown Number <optional>

The cooldown between command usage in milliseconds

cooldownExclusions Object <optional>
{}

A set of factors that limit where cooldowns are active

Name Type Attributes Description
channelIDs Array.<String> <optional>

An array of channel IDs representing channels that are not affected by cooldowns.

guildIDs Array.<String> <optional>

An array of guild IDs representing guilds that are not affected by cooldowns.

userIDs Array.<String> <optional>

An array of user IDs representing users that are not affected by cooldowns.

cooldownMessage function | String | Object <optional>

A string or createMessage() content object, or a function that returns either of those, to show when the command is on cooldown

option.cooldownReturns Number <optional>
0

Number of times to return a message when the command is used during it's cooldown. Once the cooldown expires this is reset. Set this to 0 to always return a message.

options.defaultSubcommandOptions Object <optional>
{}

Default subcommand options. This object takes the same options as a normal Command

options.deleteCommand Boolean <optional>
false

Whether to delete the user command message or not

options.description String <optional>
"No description"

A short description of the command to show in the default help command

options.dmOnly Boolean <optional>
false

Whether to prevent the command from being used in guilds or not

options.errorMessage function | String | Object <optional>

A string or createMessage() content object, or a function that returns either of those, to show if the execution of the command handler somehow fails.

options.fullDescription String <optional>
"No full description"

A detailed description of the command to show in the default help command

options.guildOnly Boolean <optional>
false

Whether to prevent the command from being used in Direct Messages or not

options.hidden Boolean <optional>
false

Whether or not the command should be hidden from the default help command list

options.hooks Object <optional>

A set of functions to be executed at different times throughout the command's processing

Name Type Attributes Description
postCheck function <optional>

A function that is executed after all checks have cleared, but before the command is executed. The function is passed the command message, arguments, and if command checks were passed as parameters.

postCommand function <optional>

A function that is executed after a response has been posted, and the command has finished processing. The function is passed the command message, arguments, and the response message (if applicable) as parameters.

postExecution function <optional>

A function that is executed after the command is executed, regardless of the final failed state of the command. The function is passed the command message, arguments, and if execution succeeded as parameters.

preCommand function <optional>

A function that is executed before any permission or cooldown checks is made. The function is passed the command message and arguments as parameters.

options.invalidUsageMessage function | String | Object <optional>

A string or createMessage() content object, or a function that returns either of those, to show when a command was improperly used

options.permissionMessage function | String | Object <optional>

A string or createMessage() content object, or a function that returns either of those, to show when the user doesn't have permissions to use the command

options.reactionButtons Array.<{emoji: String, type: String, response: (function()|String|Array.<(function()|String)>)}> <optional>

An array of objects specifying reaction buttons emoji specifies the button emoji. Custom emojis should be in format emojiName:emojiID type specifies the type of the reaction button, either "edit" or "cancel" response specifies the content to edit the message to when the reaction button is pressed. This accepts the same arguments as the generator parameter of this function, but with an extra userID parameter for generator functions (function(msg, args, userID)) describing the user that made the reaction filter specifies a function (function(msg, emoji, userID)) that filters message reactions. If the function returns false, the reaction is not treated as a valid reaction button response

options.reactionButtonTimeout Number <optional>
60000

Time (in milliseconds) to wait before invalidating the command's reaction buttons

options.requirements Object <optional>

A set of factors that limit who can call the command

Name Type Attributes Description
custom function <optional>

A function that accepts a message and returns true if the command should be run

permissions function | Object <optional>

An object or a function that returns an object containing permission keys the user must match to use the command i.e.:

{
  "administrator": false,
  "manageMessages": true
}

In the above example, the user must not have administrator permissions, but must have manageMessages to use the command

roleIDs function | Array.<String> <optional>

An array or a function that returns an array of role IDs that would allow a user to use the command

roleNames function | Array.<String> <optional>

An array or a function that returns an array of role names that would allow a user to use the command

userIDs function | Array.<String> <optional>

An array or a function that returns an array of user IDs representing users that can call the command

option.restartCooldown Boolean <optional>
false

Whether or not to restart a command's cooldown every time it's used.

options.usage String <optional>

Details on how to call the command to show in the default help command

Returns:
Type:
Command

registerSubcommandAlias(alias, label)

Register an alias for a subcommand

Source:
Parameters:
Name Type Description
alias String

The alias

label String

The original subcommand label

unregisterSubcommand(label)

Unregister a subcommand

Source:
Parameters:
Name Type Description
label String

The subcommand label