@yaas/command-handler
v2.1.3
Published
A discord.js command handler based off of nedinator's
Downloads
16
Readme
Command Handler
Installation
This one is nice and simple!
With npm:
$ npm install @yaas/command-handler
With yarn:
$ yarn add @yaas/command-handler
Usage
This is meant to simplify creating discord bots that are not single-file
const CommandHandler = require('@yaas/command-handler');
const { Client } = require('discord.js');
const client = new Client();
const CH = new CommandHandler({
folder: __dirname + '/commands/',
prefixes: ['?', '>'] // NOTE: prefixes may not contain spaces
});
client.on('message', message => {
const args = message.content.split(/\s+/g);
const command = args.shift();
const cmd = CH.get(command);
if (cmd === null) return;
try {
cmd.run(client, message, args);
} catch {
console.error(`There was an error running command: ${cmd.name}`);
}
});
This should be your file structure:
.
├── index.js
├── node_modules/
│ └── ...
└── commands/
└── test.js
This is what test.js
looks like:
module.exports = class command {
constructor() {
this.name = 'test';
this.aliases = [];
this.description = '?test';
}
async run(client, message, args) {
message.reply('Test works!');
}
};