discommands.js is an object oriented, lightweight command handler for discord.js library.
This command handler modifies discord.js's MessageCreate action class and extends client object's prototype to check if the sent message is command, before the "message" event is emitted.
Since this module modifies the action class method, I can not guarantee its backwards or future compatibility with discord.js library. Tested on discord.js 12.3.1
- Since its object oriented, its per client object based
- You can load commands from custom directories
- Or you can do manual command registration, unregistration using methods
Since its my first package ever published online, there could be some bugs. If you find some, or have an idea, contact me and i'll try to implement it or fix it.
npm install discommands.js
Node.js 12.0.0 or newer is required.
Since this command handler is object oriented, using this framework is quite easy!
require("discommands.js");
const discord = require("discord.js");
const client = new discord.Client();
const handler = client.commandHandlers.create("!");
const command = handler.commands.register("marco", "Replies to author: polo", (execMessage, args) => {
execMessage.reply("Polo!");
});
client.login("TOKEN");
require("discommands.js")
const discord = require("discord.js")
const client = new discord.Client()
client.commandHandlers.create("!", "./commands/")
client.login("TOKEN")
const command = require("discommands.js")
const command = new command("description", (execMessage, args) => {
execMessage.reply("Polo!")
})
require("discommands.js");
const discord = require("discord.js");
const client = new discord.Client();
const handler = client.commandHandlers.create("!");
//Self destructive command (one time use only)
const command = handler.commands.register("marco", "Replies to author: polo", (execMessage, args) => {
execMessage.reply("Polo!");
//delete() method (Returns true if deleted successfully)
command.delete()
//or unregister(cmdName) method (Returns true if deleted successfully)
handler.commands.unregister(command.name)
});
client.login("TOKEN");