Constructor
(abstract) new Command(info: CommandInfo)
Parameters:
Name | Type | Description |
---|---|---|
info |
|
Object containing required command properties |
- Source:
Properties
.aliases: string[]
Aliases the command can be called by other than its name
- Source:
.argOpts: ArgOpts
.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
- Source:
.client: Client
.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
- Source:
.desc: string
A brief description of the command, displayed in the commands list via the Help command
- Source:
.disabled: boolean
.external: boolean
Whether or not this command was registered via CommandRegistry#registerExternal
by some means other than the command loader like a Plugin
- Source:
.group: string
The command group that the command belongs to. Allows commands to be grouped for disabling. The group 'base' cannot be disabled.
- Source:
.guildOnly: boolean
Whether or not a command can only be used within a guild text channel
- Source:
.hidden: boolean
Whether or not the command is to be hidden from the commands list via the default help command
- Source:
.info: string
Extra information about the command to be displayed
by the Help command when help <command>
is called
- Source:
.lock: CommandLock
The CommmandLock this command uses. Must be assigned manually if locking functionality is desired
- Source:
.lockTimeout: number
Time until command locks will be cancelled if a command does not finish in time
- Source:
.name: string
The name of the command, used by the dispatcher to determine the command being executed
- Source:
.ownerOnly: boolean
Whether or not the command can be used only by the client/bot owner(s).
See: Client#config.owner
- Source:
.ratelimit: string
.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 baselimit
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
- 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
- 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 |
|
Discord.js message object |
args |
|
An array containing the args parsed from the command calling message. |
- Source:
.disable() → void
.enable() → 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:
(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 |
|
Discord.js Message object |
|
response |
|
String to send |
|
options |
|
<optional> |
Optional options for the response |
- Source:
.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 |
|
The middleware function to use |
- Source: