bot-command-loader
v1.1.5
Published
Allows easy loading and changing of commands for a bot application.
Downloads
2
Readme
Easily create and load bot commands. Simply create a directory and place your command files inside, specifying a single config
, help
, and run
property as your exports (Examples - 1). Each FILE inside your commands folder represents a single command (file name is not required to be the command name, as your properties specify such). Each FOLDER inside your commands folder represents a command group (folder name matches the group name).
Installation
npm i bot-command-loader
Usage
- function
buildList(cmdDirPath, defCmdPrefix)
: creates and returns a list of commands for the directory reading to add to. Takes the path to your command directory and your preferred default prefix as parameters. - function
createManager(cmdDirPath, defCmdPrefix)
: creates and returns a default manager to allow quick setup of parsing messages for commands and their required info. Takes the path to your command directory and your preferred default prefix as parameters.
Examples
1 (Ex. Command File Setup)
exports.config = {
enabled: true,
aliases: [],
default: false,
dm_usable: true;
};
exports.help = {
name: 'ping',
description: 'Ping/Pong command. I wonder what this does? /sarcasm',
usage: 'ping'
};
exports.run = {
discord: function(cmdParams) {
var message = cmdParams['message'];
message.channel.send('Ping?').then(function(msg) {
msg.edit(`Pong! (${msg.createdTimestamp - message.createdTimestamp}ms)`);
});
}
};
2 (Ex. Function Calls)
const CommandManager = require('bot-command-loader').createManager('./commands', '>');
const CommandList = require('bot-command-loader').buildList('./commands', '>');