Submit templates for repl.it/templates here.

← Back to all posts
Advanced Discord.js Bot Template (With database and extensions!)
h
Zavexeon

Advanced Modular Discord.js Bot Tempate

Introduction

So for a while now I've been working on a bot named Lilac2. I built I really in depth base that allows me to do a lot of things with the bot more easily. I've been suggested I strip it down and make a template using the boilerplate code I created.

Requirements

  • Firestore database with service account and key
  • Discord bot account

Setup

  1. Setup a Firestore database and generate a service account with read/write permissions.
  2. Generate a key for the account, and export it as JSON.
  3. In bot/database/key.js:
  1. In bot/config.js, set bot.token to your bot's token, and set any other properties you'd like to change, such as name, owner, developers, etc.
  2. If you have done this all correctly, run the bot! (Entry point is bot/index.js if you're not using the bash script provided)

Adding Extensions

This bot supports extensions. These are like modules for the bot, and each one can hold commands or peform actions I have included a standard extension with some commands in bot/extensions.

To add your own:

  1. Create a JS file in bot/extensions
  2. Add:

Adding Commands

  1. First, you'll you need to either create a new extension or go to the one you'd like to add commands to.
  2. If it does not exist, add a this.commands = {} to the extension's exported function. Ex:
  1. Add a property to this.commands for a command! For example:

Optional properties for commands

You can add special properties to commands to make them behave differently. For example:

All properties

  1. description A string about the purpose of a command. REQUIRED.
  2. callback What to do when the command is executed by a user. REQUIRED.
  3. cooldown Amount of milleseconds the user must wait before using the command again.
  4. hidden Hides the command from being displayed in the included help command. true | false
  5. disabled Prevents the command from being loaded into the bot, both hiding it and preventing it from being used. true | false
  6. developerOnly Whether the command is only for developers. If true, the command cannot be used by anyone not in config.developers. true | false
  7. arguments This is an array of the names for the arguments of a command. Ex: ['arg1', 'arg2']
  8. minArgs The minimum amount of arguments for a command. By default 0.
  9. maxArgs The maximum amount of arguments for a command. By default 0.
  10. permissions An array of permissions required to use the command. Uses Discord.js permission flags.

Adding Discord.js Event Listeners in Extensions

Extensions can also include their own discord.js event listeners, such as client.on('message', () => {}), however they have an alternate implentation. For example, if I want to add a message event in an extension:

This works with ALL Discord.js events and can be used multiple times. It is identical in format to regular client.on, but allows you to use them in extensions themselves.


Example Bots

Help

The fastest way to get help using this template is to join the Lilac2 Discord. This template is based upon the Lilac2 bot's source.

Voters
MCCOASTERS
FauxElements
MelvinMellow
LiliumMaid
dudeactualdev
CodingCactus
marcellll
AntonioJosJos5
Kookiez
CICCIOne
Comments
hotnewtop
EpicGamer007

pog. firebase pog.

(Also, thx for teaching me node a few months ago, i know so much more now :) )

noxitb

it doesent work

Zavexeon

@noxitb It indeed does! I've tested it out before posting, and it's based upon a bot that has been running for months now. Do you need any help? It does require some setup.

noxitb

yeah i would like some help @Zavexeon

Zavexeon

@noxitb Alrighty, could you invite me to the repl?

Iiiwiw882yahajs

@noxitb bruh learn node.js

Iiiwiw882yahajs

@noxitb it works fine!

CodingCactus

impressive

JBloves27

👍 :D

TsunamiOrSumth

wowsies, just one thing, how to firebase?

Zavexeon

@TsunamiOrSumth https://firebase.google.com/docs/firestore

Should have everything you need. If you struggle just get in contact with me on Discord in the link in the tutorial and I can give you more detailed help.