1.0.0 • Published 5 years ago

@jaimermxd/discordjs-command-handler v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

discordjs-command-handler

A simple way to implement a command handler in your discord.js project.

Installation

$ npm install discordjs-command-handler

Usage (index.js)

const Discord = require("discord.js");
const client = new Discord.Client();

const CommandHandler = require("discordjs-command-handler");

const handler = new CommandHandler({
    folder: __dirname + "/commands/",
    prefix: "p!"
});

client.on("message", message => {
    let args = message.content.trim().split(/ +/g);
    let cmd = args.shift().toLowerCase();

    let command = handler.get(cmd);
    if (command) command.run(client, message, args);
});

client.login("TOKEN");

Command example (commands/ping.js)

const Discord = require("discord.js");

module.exports.run = async (client, message, args) => {
   message.channel.send("Pong!");
}

module.exports.config = {
    name: "ping",
    aliases: ["p", "pingcommand"]
}

File structure

.
├── index.js
├── node_modules/
│   └── ...
└── commands/
    └── ping.js

CommandHandler options

The command handler supports 2 options, both of which are required strings:

  • folder - the folder where the commands are (folder: __dirname + "/commands/" works great. Do not forget to add the slashes, unless you want to get a CommandNotFoundError or something similar!)

  • prefix - the prefix the commands need (default: !. Cannot contain spaces!)

Note

This is my first npm package, so any suggestions or critics are really appreciated!

1.0.0

5 years ago