# ezcmds

> Easy command and event handler for discord.js without classes. If you would like to use the version with classes visit: https://www.npmjs.com/package/easycommands

Latest version **1.0.4** (published 2019-02-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install ezcmds
pnpm add ezcmds
yarn add ezcmds
bun add ezcmds
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2019-02-03 |
| First published | 2019-02-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | exploitz_ |

## Links

- npm: https://www.npmjs.com/package/ezcmds
- npm.io page: https://npm.io/package/ezcmds

## Dependencies (2)

- [walk](https://npm.io/package/walk.md) ^2.3.14
- [parse-ms](https://npm.io/package/parse-ms.md) ^2.0.0

## Recent versions

- 1.0.4 (latest) — 2019-02-03
- 1.0.3 — 2019-02-03
- 1.0.0 — 2019-02-03

## README

#EZCMDS

<h3>Easy command and event handler for discord.js without classes.</h3>
<h3>If you would like to use the version with classes visit: https://www.npmjs.com/package/easycommands</h3>


<h1>Set up - main file (not with event handler)</h1>

```javascript

const Discord = require("discord.js");
const client = new Discord.Client();

const { Handler } = require("ezcmds");
const handler = new Handler();

handler.register({
    client: client,
    cmdDirectory: __dirname + "/commands"
});

client.on("message",  async message => {

    if(!message.guild) return; // return if the message was sent in DMs
    const prefix = "!"; // define prefix
    if(!message.content.startsWith(prefix)) return; // if the message content doesn't start with our prefix return.

    const messageArray = message.content.split(/ +/g); // split the message content at every space
    const cmd = messageArray[0].toLowerCase().slice(prefix.length); // get the command that was run
    const args = messageArray.slice(1); // define your args

    handler.run(cmd, client, message, args); // will run command if it is found. Will also catch errors.


    // client.handler.run(cmd, client, message, args); if your event is in a seperate folder you may still access the handler through client.handler

});

client.login("bot token goes here");

```

<h3>Example Command inside ./commands/test.js</h3>

```javascript

exports.run = async (client, message, args) => {

    // code goes here.


    message.channel.send("Test done!");


}

exports.help = {
    name: "test", // required
    aliases: ['test1', 'test2'], // optional. 
    cooldown: 60000 // optional. in milliseconds
}


```

<h1>Example using event handler. Main file:</h1>


```javascript

const Discord = require("discord.js");
const client = new Discord.Client();

const { Handler } = require("ezcmds");
const handler = new Handler();

handler.register({
    client: client,
    cmdDirectory: __dirname + "/commands",
    evtDirectory: __dirname + "/events"
});


client.login("bot token goes here.");


```

<h3>Inside ./events/message.js</h3>

```javascript


exports.run = async (client, message) => {

    if(!message.guild) return; 
    const prefix = "!"; 
    if(!message.content.startsWith(prefix)) return; 
 
    const messageArray = message.content.split(/ +/g); 
    const cmd = messageArray[0].toLowerCase().slice(prefix.length); 
    const args = messageArray.slice(1); 
 
    client.handler.run(cmd, client, message, args);



}


```

<h3>The command example will remain the same as above. </h3>


<h2>Bonus: Using the handler and being able to pass additional variables. </h2>
<h3>Inside ./events/message.js</h3>

```javascript

exports.run = async (client, message) => {

        if(!message.guild) return; // return if the message was sent in DMs
        const prefix = "!"; // define prefix
        if(!message.content.startsWith(prefix)) return; // if the message content doesn't start with our prefix return.
     
        const messageArray = message.content.split(/ +/g); // split the message content at every space
        const cmd = messageArray[0].toLowerCase().slice(prefix.length); // get the command that was run
        const args = messageArray.slice(1); // define your args
     
       const cool = client.handler.checkCooldown(message.author.id, message.guild.id, cmd); // want to remove cooldowns? Remove this line and the following:

       if(cool) return message.channel.send(`You must wait ${cool.hours}h ${cool.minutes}m ${cool.seconds}s before using this command again.`); // remove this line too

       const command = client.handler.get(cmd);
       if(!command) return;

       command.run(client, message, args, "extra", "variables", "now", "work");

       client.handler.setCooldown(message.author.id, message.guild.id, cmd); // remove this line too
     
}


```

<h3>Then inside ./commands/test.js</h3>


```javascript


exports.run = async (client, message, args, extra1, extra2, extra3, extra4) => {

    message.channel.send(`${extra1} ${extra2} ${extra3} ${extra4}`);

    // expected output: "extra variables now work"


}


exports.help = {
    name: "test"
}


```

---
_Source: https://npm.io/package/ezcmds · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
