![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
discord-message-handler
Advanced tools
Message and command handler for discord.js bots and applications.
##About discord-message-handler is a module written to simplify message and command handling for discord.js bots and applications.
##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:
const MessageHandler = require('discord-message-handler');
Define rules for the message handler (shown below) then parse messages in the as they arrive:
client.on('message', message => {
MessageHandler.handleMessage(message);
});
###Simple message handlers
MessageHandler.whenMessageContainsWord("shrug").reply("¯\\_(ツ)_/¯");
MessageHandler.whenMessageContains("lol").replySometimes("kek", 50);
MessageHandler.whenMessageContainsExact("dota").replyOne(["volvo pls", "rip doto"]);
MessageHandler.whenMessageContainsOne(["br", "brazil"]).reply("huehue");
MessageHandler.whenMessageStartsWith("help").then(message => doSomething(message));
###Command handler
MessageHandler.onCommand("/doit").do((args, rawArgs, message) => {
message.channel.sendMessage(`Doing something for ${message.author}...`)
});
###Commands with usage info
MessageHandler
.onCommand("/info")
.minArgs(2)
.whenInvalid("Invalid command. Usage: /info <a> <b>")
.do((args) => {
doSomething(args[0]);
doSomethingElse(args[1]);
});
###Case sensitivity In case you want message filters to be case sensitive you just need to call this function once:
MessageHandler.setCaseSensitive(true);
By default all message filters are case insensitive. (false)
###Logging
To enable logging call MessageHandler.enableLogging()
and pass a function to handle logs.
MessageHandler.enableLogging((filterType, filter, message) => {
console.log(`${new Date().toISOString()} ${filterType}: ${filter} - "${message.content}"`);
});
##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.
FAQs
Message and command handler for discord.js bots and applications.
The npm package discord-message-handler receives a total of 3 weekly downloads. As such, discord-message-handler popularity was classified as not popular.
We found that discord-message-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.