This is an Advanced Command Handler, which uses classes for commands.
Configuration
To install the command handler, install npm and then in a terminal run this command where you want your bot npm i advanced-command-handler.
After it create your main file and add this into it :
const {CommandHandler} = require('advanced-command-handler');
CommandHandler.create({
commandsDir: 'name of the dir',
eventsDir: 'name of the dir',
// Optionnals :
prefixes: ['!', 'coolPrefix '],
owners: ['Discord IDs']
});
CommandHandler.launch({
token: "YOUR TOKEN GOES HERE",
// Optionnal :
clientOptions: {
// Client Options, see Discord.js#ClientOptions
}
});CommandHandler Class
| Field | Description | Type |
|---|---|---|
| instance | Represents the instance of the CommandHandler. | Object |
| owners | Owners that you put in the CommandHandler.create method. |
SnowFlake[] |
| prefixes | Prefixes that you put in the CommandHandler.create method. |
String[] |
| client | Represents the Client of the bot, see in the helpers section for the other methods. | Client extends Discord.Client |
| commands | All the commands that have been found by command handler on the launch. | Discord.Collection<String, Command> |
| create(options) | Creates a command handler and reset all data save in instance. | return void |
| launch(options) | Launch the Command Handler by login in the Client and fetching Commands/Events | return void |
Templates
Commands
const {Command} = require('advanced-command-handler');
module.exports = new Command({
name: '',
description: '',
// Optionnals :
usage: '',
category: '',
nsfw: false,
guildOnly: false,
ownerOnly: false,
aliases: [],
userPermissions: [],
clientPermissions: [],
}, async(client, message, args) => {
// Your code goes here.
});You have to put the command into a category folder into your commands folder like in the example.
This is an example, the message event is not integrated into the command handler, you have to create it yourself !
Events
module.exports = async(handler, ...EventArguments) => {
// Your code goes here.
};The file's given name set out which event it handles.
Logger Class
Logger is a class in the utils folder to helps you creating logs.
It has multiple static methods :
| Name | Description | Color |
|---|---|---|
comment( message, typeToShow = 'comment' ) |
Let you log something with the showed type COMMENT, theses only logs if the static field logComments is set to true. |
grey : #6e6f77 |
error( message, typeToShow = 'error' ) |
Let you log something with the showed type ERROR. |
red :#b52825 |
event( message, typeToShow = 'event' ) |
Let you log something with the showed type EVENT. |
#43804e |
info( message, typeToShow = 'info' ) |
Let you log something with the showed type INFO. |
blue : #2582ff |
log( message, type = 'log', color = 'log' ) |
Let you log something with the showed type LOG, you can change the color. |
default :#cccccc |
test( message, typeToShow = 'test' ) |
Let you log something with the showed type TEST. |
white : #ffffff |
warn( message, typeToShow = 'warn' ) |
Let you log something with the showed type WARN. |
yellow : #eeee23 |
setColor(color = 'default', text = '', colorAfter = '') |
Let you change the color after the function or the color of the text only, and let you change the color after the text if you set the argument. |
color |
Example
const {Logger} = require('advanced-command-handler');
Logger.error(`${Logger.setColor('orange', 'Command')} is not allowed.`, 'PermissionError');Give the following result in the console (screen made on WebStorm).
Every number is yellow by default.
Colors for the logger
Colors are set out in static public object in the Logger class, so you can change them.
These are the current colors :
colors = {
red : '#b52825',
orange : '#e76a1f',
gold : '#deae17',
yellow : '#eeee23',
green : '#3ecc2d',
teal : '#11cc93',
blue : '#2582ff',
indigo : '#524cd9',
violet : '#7d31cc',
magenta: '#b154cf',
pink : '#d070a0',
brown : '#502f1e',
black : '#000000',
grey : '#6e6f77',
white : '#ffffff',
default: '#cccccc'
}Helpers
BetterEmbed
This is a class for creating Embed Object, but a bit simpler like this :
// Embed Objet :
const embed = {
image: {
url: 'url'
},
fields: [{
name: 'name',
value: 'value'
}],
author: {
name: 'name',
icon_url: 'icon_url'
}
}
const {BetterEmbed} = require('advanced-command-handler');
// BetterEmbed
const embed = new BetterEmbed({
image: 'url',
author: 'name',
author_icon : 'icon_url'
});
embed.fields.push({
name: 'name',
value: 'value'
});
// Using templates
BetterEmbed.templates.funny = {
title: '${client.user.username} says that you are funny !'
}
const embed = BetterEmbed.fromTemplate('funny', {client: message.client});
message.channel.send({embed: embed.build()});This can simplify your embeds declarations.
Useful functions
There are multiple utils functions that can be use (require them like other classes).
| Name | Description | Returning |
|---|---|---|
argError( channel, error, command ) |
Send an embed that explains the argument error and show correct the syntax. | Embed Object |
async getThing( datatype, text ) |
Search for the dataType (like an user or command) into the client and in the text. If text is a message it will looks into its mentions. |
Object (datatype) or false |
The Command class has a method deleteMessage( message ) to safely delete messages without sending Errors (missing permissions).
The Client class has multiples methods also :
| Name | Description | Returning |
|---|---|---|
hasPermission( message, permission ) |
Check if bot has permission permission. |
Boolean |
isOwner( id ) |
Check if the id is in the owners (configuration). |
Boolean |
