Base bot for Discord

License: MIT

Language: JavaScript


This is a base bot for Discord using Javascript.



This module requires

Install with NPM

npm install --save discord-bot-base


The goal of this repository, is to make it simple to create a bot, and add on commands. To get started just create an instance of Bot.

'use strict';

const BaseBot = require('discord-bot-base');
const TestCommand = require('./src/Command/TestCommand')

new BaseBot.Bot('dev', true, {
    admin_id:  '<your user id>',
    email:     '<your bot login>',
    password:  '<your bot password>',
    log_dir:   '<location of logs directory>',
    commands:  [TestCommand],
    prefix:    "!",

The arguments passed to Bot are first, the environment (generally 'dev' or 'prod'), debug (adds extra logging), and an array of options.

The keys that are provided to options (admin_id, email, password, commands, and prefix are all required).

Below is a list of options you can pass:

  • name - Name of the bot. This is just for the output on the CLI. Not necessary, and will default to discord-base-bot
  • version - Version of the bot. This is also just for the output on the CLI. Not necessary, and will default to the current version of discord-base-bot
  • author - Author of the bot. This is again, just for the output on the CLI. Not necessary, and will default to the author of discord-base-bot
  • status - Status of the bot. Will show up in the user list as "Playing "
  • email - Login for the bot. This is required.
  • password - Password for the bot. This is required.
  • prefix - Prefix the bot will use for commands. This is required. Try not to use common characters if you plan to be on big servers.
  • admin_id - User ID of the account you want to have access to admin commands. (e.g. the restart command)
  • container - Advanced. For now, if you need to add this, message me in the discord api server. Required to use mysql/mongo/redis stuff.
  • commands - An array of commands. The array should contain modules of commands. Check out an example below of a command.
  • mongo_url - a Fully qualified mongo dsn. e.g. mongodb://localhost/
  • redis_url - a Fully qualified redis dsn. e.g. redis://localhost/
  • queue - An object of config variables for rabbitmq

If you specify queue, you will be able to set up your bot with cluster support, with PM2.

Command Example

Below, is what the Stats command looks like:

const AbstractCommand = require('discord-base-bot').AbstractCommand;

class StatsCommand extends AbstractCommand {
    static get name() { return 'stats'; }

    static get description() { return "Shows the bot stats"; }

    handle() {
        this.responds(/^stats$/g, () => {
            let servers  = this.client.servers.length,
                channels = this.client.channels.length,
                users    = this.client.users.length,
                online   = this.client.users.filter(u => u.status != "offline").length;

                `Currently joined to: ${servers} servers with ${online}/${users} members and ${channels} text channels.`

module.exports = StatsCommand;

Take note of the static getters at the top. These are used for the help command.

All commands are required to extend AbstractCommand. AbstractCommand provides a couple helper methods. A few to note are:

  • responds - Used when you want the bot to respond to a direct mention, or command. Takes a regex, with the second argument being a callback if a match was found. The callback is passed an array of matches.
  • hears - Used when you want the bot to listen for a phrase. Takes a regex, with the second argument being a callback if a match was found. The callback is passed an array of matches.
  • sendMessage - Shortcut for discord.js's client.sendMessage
  • reply - Shortcut for discord.js's client.reply, just pass a message.
  • isThrottled - Lets you throttle commands. Pass a key, and how long (in seconds) to throttle for.
  • handle - This method is required for all commands as well. All your logic should go in here.

Project Statistics

Sourcerank 4
Repository Size 1.94 MB
Stars 4
Forks 6
Watchers 2
Open issues 1
Dependencies 21
Contributors 1
Tags 95
Last updated
Last pushed

Top Contributors See all

Aaron Scherer

Packages Referencing this Repo

Javascript bot base for Discord
Latest release 6.0.2 - Updated - 4 stars

Recent Tags See all

v6.0.2 April 18, 2016
v6.0.1 April 13, 2016
v6.0.0 April 08, 2016
v5.0.24 April 07, 2016
v5.0.23 April 06, 2016
v5.0.22 April 06, 2016
v5.0.21 April 06, 2016
v5.0.20 April 06, 2016
v5.0.19 April 06, 2016
v5.0.18 April 06, 2016
v5.0.17 April 05, 2016
v5.0.16 April 05, 2016
v5.0.15 April 02, 2016
v5.0.14 April 02, 2016
v5.0.13 April 02, 2016

Something wrong with this page? Make a suggestion

Last synced: 2016-05-27 19:26:31 UTC

Login to resync this repository