# bot-cmd

> Discord Bot Boilerplate

Latest version **1.4.1** (published 2021-08-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install bot-cmd
pnpm add bot-cmd
yarn add bot-cmd
bun add bot-cmd
```

Provides the command `bot-i`.

## 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.4.1 |
| Published | 2021-08-16 |
| First published | 2021-03-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | BlobKat#1337 |
| Maintainers | matreiner |
| Keywords | discord, bot, command |

## Links

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

## Dependencies (1)

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

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.4.1 (latest) — 2021-08-16
- 1.4.0 — 2021-06-24
- 1.3.9 — 2021-06-24
- 1.3.8 — 2021-06-24
- 1.3.7 — 2021-04-21
- 1.3.6-hotfix — 2021-04-21
- 1.3.6 — 2021-04-21
- 1.3.5-hotfix3 — 2021-04-21
- 1.3.5-hotfix2 — 2021-04-19
- 1.3.5-hotfix — 2021-04-19
- 1.3.5 — 2021-04-19
- 1.3.4 — 2021-03-31
- 1.3.3 — 2021-03-30
- 1.3.2-hotfix — 2021-03-30
- 1.3.2 — 2021-03-30
- … 33 more at https://npm.io/package/bot-cmd/versions

## README

# What it does
It's a discord and firebase boilerplate (the base code) combined with a really cool command handler and a few extra features
# How to setup

```js
let bot = require("bot-cmd")(TOKEN, FIREBASE_TOKEN, OPTIONS)
//no need for bot.on("message", ...)
bot.set({
  prefix: "p!", //supports regex
  pingHint: "Message to say when bot gets pinged",
  errorHint: "Message to say when error occurs"
})
```

# Basic Usage
```js
bot.cmd("ping", function(msg){ //Use bot.cmd for commands with prefix
  msg.reply("Pong!")
}
bot.cmd("say :str", function(msg, string){ //parameter
  msg.channel.send(string)
})
bot.cmd("xp", function(msg){
  msg.channel.send("Level of user: "+this.user.level)
  //"this" is an object containing useful data such as user data
  // and guild data
})
bot.cmd("avatar :user", function(msg, user){
  //automatically converts parameter to a user object
  if(user){
    msg.channel.send(user.avatarURL({size:256}))
  }else{
    msg.channel.send("Couldn't find user")
  }
})
bot.cmd("total ::int",function(msg, nums){
  //:: means a spread parameter (the rest of parameters)
  //so "p!total 1 2 3" will make "nums" be [1,2,3]
  msg.reply(`The total is ${nums.reduce( (a,b)=>a+b )}`)
}
bot.cmd(":", function(msg, a){ //: is wildcard: it means any type
  //note that wildcards work like the ::
  //you can't have anything else after it

  //we can use this as a fallback for an invalid command
  msg.reply("Invalid command lol")
})
bot.msg(":int", function(msg, num){ //bot.msg = prefix-less command
  //counting command, I'll let you code it yourself!
  return true; //returning true will allow other commands to run
  //(if there are any other matching commands)
})
/*
Note: handlers run top-to-bottom,
by default, only the first applicable handler runs per message. Make a handler "transparent" (won't block other handlers) by returning true
bot.cmd("...", function(...){
  ...
  return true;
})
You can add your own types using this function:
bot.type(/regexToMatch/, (string, msg) => parseType(string))
*/
```
# this
`this` refers to an object which contains `user`, the userdata (from firebase), `guild` (the guilddata from firebase) and `member` (guild-specific user data)
any modifications to `this` is tied to the message (it will be available to all other handlers for this specific message). This feature can be used to calculate data before a command is ran, instead of calculating it for every command. Example:
```js
bot.msg(":", function(msg){ //for every command used
  this.userLevel = this.user.xp / 1000
  this.authorIsAdmin = (msg.author.id == "123456789123456789")
  return true //If you don't return true no other command handler can run after this one
})
...
bot.cmd("ban :user", function(msg, user){ //example command
  if(this.authorIsAdmin){
    //ban the user
  }
})
```
To install firebase (for user/guild data), run `npx bot-i` after having installed this module
# Supported types

`:int` - an integer (series of digits)

`:num` - any number, including decimals

`:str` - string (text)

Note: to have spaces in a string when *using* the command, put the quotes around the string (for example, `p!say "hello world"`)

`:bool` - a boolean, supports yes/no, true/false, 1/0, but we convert it to a regular boolean for you

`:user` - a discord user, or `null` if it's invalid

`:member` - same as user, except they must be in the guild

`:channel` - a discord channel, or `null` if it's invalid

`:role` - a role that's in the server

## [Issues](https://github.com/MatReiner/bot-js/issues)

## Extra features

`bot.ai(text, channelID): Promise<string>` - Chat AI (install module using `npx bot-i`)

`OPTIONS` (parameter):
```js
{
  ai: bool, //Use bot.ai?
  member: bool, //Use this.member?
  user: bool, //Use this.user?
  guild: bool, //Use this.guild?
  clientOptions: Discord Client Options,
  svgProxy: string //https://svg.to.png/convert.png?svgCode=$
}
```

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