A simple and lightweight Discord.js command handler builder.
npm install handle.djsA simple and lightweight Discord.js command handler builder.
In your terminal, type the following command:
```
npm i handle.djs@latest
Heres an example of how to make a handler!
Create a file called handler.js in your root directory (or wherever you have your bot's file):`js
const Handler = require('handle.djs');
const CommandHandler = new Handler();
CommandHandler.set('prefix', '!')
CommandHandler.register('ping', msg => {
msg.channel.send('Pong!');
});
module.exports = CommandHandler;
`
Then, you need to import your CommandHandler into your bot file, as well as add a Client#on('message') method with the callback set to CommandHandler#handle:
`js
const CommandHanlder = require('./handler');
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log('Im ready!');
});
client.on('message', CommandHandler.handle);
client.login(process.env.YOUR_BOT_TOKEN);
`
- [Class] Handlernew Handler()
- Constructor: [func] set(type, value)
- Methods:
- Handler#set('prefix', '!')
- Sets a config variable for your handler
- Examples:
- [func] register(cmd, callback, options)
- Handler#register('ping', msg => msg.channel.send('Pong!'))
- Registers a command that can be handled
- Examples:
- Handler#register('hi', msg => msg.channel.send('Hey!'), { prefixed: false })
- [bool] Prefixed
- Options:
- [func] handle(msg, ...data)
- Determines whether or not if the command handler should check if the command was ran with the prefix
- Handler#handle(message)
- Handles a command by command name
- Examples:
- Client#on('message', Handler.handle)` method.
- Please note this should not be called anywhere other than in a
Want to contribute to handle.djs? Great! You can make a pull request, fork the project, or submit an issue on our GitHub, here!