Hyperz Documentation > Products > Dark Bot > Backend Stuff

Backend Stuff


Table of Contents

Extension Handler

Our new extension hander (released in 1.3) now searches folders rather than just plain js files in the extensions folder. With this change, all extensions must now include a extension.json file that has the below data inside of it.

    "name": "My Extension",
    "version": "1.0.0",
    "author": "Unknown#0000",
    "file": "main.js"

This is the file that the extension loader will read off of when loading each extension and deciding which file to execute. If the file does not exist, the entire extension will be ignored.

You can see what each of these JSON Params mean below:

  • name is the name of your extension.
  • version is the version # of your extension.
  • author is who created the extension.
  • file is the file that the extension loader should look for and execute.

When creating an extension, follow the below main.js file template.

module.exports = async function(client, con, app) {
    // client = Discord Bot Client
    // client.darkbot = Custom event emitter (released in 1.3 update)
    // con = Database Connection
    // app = Express App

Dark Bot Emitter

With Dark Bot 1.3 we are introducing a new way to create extensions with Dark Bot! We have now created our very own event emitter. You can access it through client.darkbot.

The purpose of using client.darkbot is to make sure that events are only fired when the rest of the required pre-requisites are completed.

Below is an example of how to listen to events made through the new event emitter:

client.darkbot.on('eventName', function(args) {

and below here you will find an example of how to emit custom events to listeners:

client.darkbot.emit('eventName', ("Hello world!"));

A current list of all Dark Bot factory events can be found below:

  • botReady - Emitted when the bot has started and completed all start-up events.
  • extensionInteraction - When an interaction is received but not factory recognized.

The max amount of event listeners by default is 99.

External Calling

We are also aware that not every function might pass client as a parameter. To counter this, we have also included the following global variables to assure that these endpoints can be accessed globally around the application.

PLEASE NOTE: We do not expect you to use these global variables in situations that do not require them. Extensions that get passed in pull requests that use these global variables where they are not required or needed, will be denied.

Using global variables when programming is never a good idea, however, they do exist for a reason.

Global Variables

  • global.darkClient = client (discord.js client).
  • global.darkCon = con (database connection).
  • global.darkApp = app (express application).
  • global.darkEvents = client.darkbot (custom emitter).
  • global.darkLangs = client.languages (all stored language files).

Was this article helpful?

52 out of 108 found this helpful