Skip to content
Sign upLog in
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs

Advanced Discord.js Bot Template (With database and extensions!)


March 2022 - Locking this, it's out of date and broken, keep getting notifs for it. - Zave

Advanced Modular Discord.js Bot Tempate


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.


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


  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:
module.exports = /* firestore json key */
  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:
module.exports = function(context) { = 'Extension name here!' // required this.description = 'Extension description here!' // required /* whatever code you want the extension to do in here */ }

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:
module.exports = function(context) { = 'Extension name here!' // required this.description = 'Extension description here!' // required /* whatever code you want the extension to do in here */ this.commands = {} }
  1. Add a property to this.commands for a command! For example:
this.commands = { 'my-cmd': { /* description and callback are required in a command */ description: 'lol this is my command' callback: message => { /* what to do when a user uses the command */ } } }

Optional properties for commands

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

'my-cmd': { cooldown: 5000, // cooldown of 5000 ms (5 secs) minArgs: 1, // minimum args the commnd takes maxArgs: 1, // maximum args the commands takes permissions: ['MANAGE_MESSAGES'] // permissions needed to use command arguments: ['arg-1'] // the arguments names callback: (message, arguments) => { console.log(arguments['arg-1']) } }

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:

module.exports = function(context) { = 'foo' this.description = 'bar' context.botOn('message', message => { /* do stuff here */ }) }

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


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.

2 years ago
You are viewing a single comment. View All

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.

2 years ago