# commanding.js

> A Discord.JS Command Handler to handle commands eaiser

Latest version **1.2.0** (published 2022-06-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install commanding.js
pnpm add commanding.js
yarn add commanding.js
bun add commanding.js
```

## 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.2.0 |
| Published | 2022-06-05 |
| First published | 2022-05-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 86.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | AaTherf |
| Maintainers | aatherf |
| Keywords | Discord.js, discord, commandhandler, commanding, commands, commandingjs |

## Links

- npm: https://www.npmjs.com/package/commanding.js
- Repository: https://github.com/CodyAaTherf/commanding.js
- Homepage: https://github.com/CodyAaTherf/commanding.js#readme
- Issues: https://github.com/CodyAaTherf/commanding.js/issues
- npm.io page: https://npm.io/package/commanding.js

## Dependencies (2)

- [mongoose](https://npm.io/package/mongoose.md) ^6.3.5
- [discord.js](https://npm.io/package/discord.js.md) ^13.7.0

## Recent versions

- 1.2.0 (latest) — 2022-06-05
- 1.1.1 — 2022-06-04
- 1.1.0 — 2022-05-30
- 1.0.0 — 2022-05-15

## README

# TABLE OF CONTENTS

- [Installation](#installation)
- [Setup](#setup)
- [Changing Default Prefix](#prefixes)
- [Creating a Command](#creating-a-command)
- [Usage of minArgs and maxArgs](#minargs--maxargs)
- [Syntax Errors](#syntax-error)
    - [Global Syntax Errors](#global-syntax-error)
    - [Per Command Syntax Error](#per-command-syntax-error)
- [Permissions](#permissions)
- [MongoDB Connection](#mongodb-connection)
- [Built in Commands](#built-in-commands)
- [Sources](#sources)

# Installation

**NPM**
```bash
npm i commanding.js
```

You can install the latest work in progress by -

```bash
npm i "https://github.com/CodyAaTherf/commanding.js#dev"
```

Note that these features are still in work in progress and some might not have been completed yet and your bot might break. You can check on to [here](https://github.com/CodyAaTherf/commandingjs-tests) to know more!

# Setup

How to setup commanding.js -

```js
const { Client , Intents } = require('discord.js')
const CommandingJS = require('commanding.js')
const { token } = require('./config.json')

const client = new Client({ intents: [Intents.FLAGS.GUILDS , Intents.FLAGS.GUILD_MESSAGES] });

client.once('ready' , () => {
    console.log("Ready!");

    new CommandingJS(client , 'commands')
})

client.login(token)
```

# Prefixes

The default prefix of the bot on installing this package will be - `>` .
You can change it in your main file using -

```js
new CommandingJS(client)
    .setDefaultPrefix('!')
```

# Creating a Command

Here's how to create a ping command -

```js
module.exports = {
    name: 'ping' , // required
    commands: ['p'] ,
    description: 'Ping' , // optional
    callback: (message) => {
      message.reply('Pong!')
    }
}
```

You can either use `commands: ['']` or `aliases: ['']` , either works but you have to use one atleast.

Users can use `>ping` or `>p` and use the command.

# minArgs & maxArgs

Minimum and Maximum number of args a user has to use before they can use the command. In this example the bot will ping the user you ping.

```js
// ping-member.js

module.exports = {
    name: 'ping-member' ,
    commands: ['ping-member' , 'pingmember' , 'pm'] ,
    description: 'Bot pings the member you ping' ,
    minArgs: 1 ,
    maxArgs: 1 ,
    callback: (message) => {
        const { mentions } = message
        const target = mentions.users.first()

        if(target){
            message.channel.send(`Hello , ${target} !`)
        }
    }
}
```

Note - `minArgs` cannot be less than `maxArgs` or you will get an error.

# Syntax Error

## Global Syntax Error -

The default syntaxError is `Wrong Syntax` !
You can change it in your main file using -

```js
new CommandingJS(client)
    .setSyntaxError("")
```

## Per-Command Syntax Error -

You can specify the syntax error for each command using -

```js
module.exports = {
    name: 'ping-member' ,
    commands: ['ping-member' , 'pingmember' , 'pm'] ,
    description: 'Bot pings the member you ping' ,
    syntaxError: 'wrong symtax! use {PREFIX}{COMMAND} <@mention>' ,
    minArgs: 1 ,
    maxArgs: 1 ,
    callback: (message) => {
        const { mentions } = message
        const target = mentions.users.first()

        if(target){
            message.channel.send(`Hello , ${target} !`)
        }
    }
}
```

You can use -
`{PREFIX}` - to show the bot's perfix on the Error

`{COMMAND}` - command name

# Permissions

Making a ban command or any other command that requires permissions? You can do it by -

```js
module.exports = {
    name: 'ping' ,
    commands: ['p'] , // or aliases: ['p'] . either works
    description: 'Ping' ,
    requiredPermissions: ['ADMINISTRATOR'] ,
    callback: (message) => {
      message.reply('Pong!')
    }
}
```

[Here](./src/permissions.ts) are all the permissions that you might have to use.

# MongoDB Connection

MongoDB Connection is optional. You will need it to use the built in commands or any commands that you use that requires to save data.
You can define it in the main file using -

```js
// index file

const config = require('./config.json')

new CommandingJS(client)
    .setMongoPath(config.mongo_uri)
```

config.json

```json
{
    "token": "" ,
    "mongo_uri": ""
}
```

# Built in commands -

`>prefix` - Displays the prefix of the bot

`>prefix <new prefix>` - Changes the prefix of the bot. It is supported per server. Required MongoDB Connection. See [MongoDB Connection](#mongodb-connection) to know to to connect to MongoDB.

`>command <enable | disable> <command name>` - Enable or Disable any command. It is supported per server. Requires MongoDB Connection. 

`>commands` - Displays **all** the current commands of the bot.

# SOURCES

All these snippets have come from [Commanding.JS Test Repository](https://github.com/CodyAaTherf/commandingjs-tests). It has been maintained by me itself.

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