bot-cmd

1.4.1 • Public • Published

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

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

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:

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

Extra features

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

OPTIONS (parameter):

{
  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=$
}

Readme

Keywords

Package Sidebar

Install

npm i bot-cmd

Weekly Downloads

3

Version

1.4.1

License

MIT

Unpacked Size

13 kB

Total Files

4

Last publish

Collaborators

  • blobkat