handle.djs
v0.0.1
Published
A simple and lightweight Discord.js command handler builder.
Downloads
5
Maintainers
Readme
Handle.djs
A simple and lightweight Discord.js command handler builder.
Installation
In your terminal, type the following command:
npm i handle.djs@latest
Examples
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):
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
:
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);
Syntax
[Class]
Handler
- Constructor:
new Handler()
- Methods:
[func] set(type, value)
- Sets a config variable for your handler
- Examples:
Handler#set('prefix', '!')
[func] register(cmd, callback, options)
- Registers a command that can be handled
- Examples:
Handler#register('ping', msg => msg.channel.send('Pong!'))
Handler#register('hi', msg => msg.channel.send('Hey!'), { prefixed: false })
- Options:
[bool] Prefixed
- Determines whether or not if the command handler should check if the command was ran with the prefix
[func] handle(msg, ...data)
- Handles a command by command name
- Examples:
Handler#handle(message)
- Please note this should not be called anywhere other than in a
Client#on('message', Handler.handle)
method.
- Constructor:
Requirements
- Discord.js
Contributing
Want to contribute to handle.djs? Great! You can make a pull request, fork the project, or submit an issue on our GitHub, here!