About
discord-message-handler is a module written to simplify message and command handling for discord.js bots and applications.
Table of Contents
Installation
Simply navigate to your project's folder and type npm install discord-message-handler --save
on the command line.
Usage
To start using the module you must require it into you script like this (changed in 2.0)
Old style require:
const MessageHandler = MessageHandler;const handler = ;
ES2015:
const MessageHandler = ;const handler = ;
Typescript:
;;
Define rules for the message handler (shown later in the next sections) then parse messages in the as they arrive:
client;
Simple message handlers
handler;handler; // 33% chancehandler;handler;handler;
Command handler
handler;
Commands with alias
handler;
Commands with usage info
handler ;
Commands with regex validation
handler
Command invocation deletion
You can automatically delete the message that triggered a command using the deleteInvocation
method. The time argument is optional, and if absent the message will be deleted imediatelly.
// User's message will be deleted after 1500mshandler;
Example handling messages across multiple files
Consider you have the following structure:
├── commands
│ ├── greetings.js
│ └── helper.js
└── index.js
greetings.js:
moduleexports { handler; handler;}
helper.js:
const MessageHandler = ; moduleexports { /* [Optional] You can recreate the handler using the parent context so your IDE will properly give out suggestions for the handler */ const myhandler = handler; myhandler; myhandler;}
index.js:
const MessageHandler = ;const greetingsCommands = ;const helperCommands = const handler = ;greetingsCommands;helperCommands; // (...) code continues
Case sensitivity
In case you want message filters to be case sensitive you just need to call this function once:
handler;
By default all message filters are case insensitive. (false)
Logging
To enable logging call handler.enableLogging()
and pass a function to handle logs.
handler;
Contributing
Feel free to send a pull request or open an issue if something is not working as intended or you belive could be better.