# Command Abstract
Abstract base class for all Chariot.js commands. Every command created must extend this class, otherwise Chariot.js won't register the command upon initialization. This class should never be instantiated as-is without being extended!
A highly detailed command template along with explanations and command examples can be found here.
# Constructor
Instantiation: In command subclass via super();
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
No constructor parameters |
# Properties
# name Instantiation
The command's name. This is the main identifier your command can be invoked with.
Type:String
# aliases Instantiation
An array of aliases a command can be invoked with besides its main name.
Type:Array<String>
# subcommands Instantiation
An array of sub-command names a command has and can be sub-invoked with.
Type:Array<String>
# permissions Instantiation
An array of permissions the bot client must have to be able to run the command.
Type:Array<String>
# userPermissions Instantiation
An array of permissions the user invoking the command must have to be able to run the command.
Type:Array<String>
# owner Instantiation
Whether the command can only be executed by bot owners specified within the config object.
Type:Boolean
# nsfw Instantiation
Whether the command can only be executed within text channels that have been labeled NSFW.
Type:Boolean
# allowDMs Instantiation
Whether the command can be used within a private text channel in DMs.
Type:Boolean
# cooldown Instantiation
The amount in seconds a command should be on cooldown for the user invoking it after it has been invoked.
Type:Number
# help Instantiation
An object containing help properties for the built in help system. More information under Typedefs or the Examples.
Type:Object
# Methods
# execute(message, args, chariot) Abstract
A command's main method getting executed by the MessageHandler upon a valid invocation request.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
message | Eris.Message | N/A | The emitted message object that invoked this command | |
args | String[] | N/A | An array containing all provided arguments | |
chariot | Client | N/A | The Chariot.js bot client extending Eris.Client |
Promise<void>
This method resolves with an empty Promise upon successful completion.
async execute(message, args, chariot) {
message.channel.createMessage(`This bot is in ${chariot.guilds.size} guilds!`);
}
# runPreconditions(message, args, chariot, next) Abstract | Optional
Precondition testing method. This method will run before the main command logic and is fully optional.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
message | Eris.Message | N/A | The emitted message object that invoked this command | |
args | String[] | N/A | An array containing all provided arguments | |
chariot | Client | N/A | The Chariot.js bot client extending Eris.Client | |
next | Function | N/A | Marking testing as done, invoking the main executor |
Promise<void>
This method resolves with an empty Promise upon successful completion.
async runPreconditions(message, args, chariot, next) {
if (args.length > 3) {
next();
} else {
return message.channel.createMessage('Insufficient amount of arguments!');
}
}
# tailedArguments(string, delimiter, count)
Simple argument handler for getting tailed arguments with custom length and delimiters.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
string | String | N/A | A string to be used. E.g. message.content | |
delimiter | String | N/A | A delimiter to split the string by. E.g. a space | |
count | Number | N/A | How often to split by the delimiter before merging |
Array<String>
An array of all generated arguments with the last element being the merged result.
const content = 'Hello my name is John';
const arguments = this.tailedArguments(content, ' ', 2); /* arguments ⇨ ['Hello', 'my', 'name is John'] */