Skip to content
This repository has been archived by the owner on Aug 18, 2019. It is now read-only.

Creating plugins🔌

Eric Rabil edited this page Jun 5, 2017 · 3 revisions

Creating a plugin (or module, as they will be referred to for the rest of the wiki entry) is very, very simple. Almost stupid. It consists of two to three steps, and then you're all set!

Modules are designed as a replacement for hooking into DDBot and changing functionality for other commands or hooks. They have an event and command system so you do not have to modify the actual client for typical scenarios.

1. Create your module.json file

The module.json file is the "roadmap" of your module. It tells DDBot where the main module file is, the module identifier and commands directory (if present.) This is required, and if it is missing your module will simply be skipped.

  1. Create your module directory. In this example, it will be called "MyModule"
  2. In your newly created directory, create a file called module.json and copy the following into the file:
{
    "identifier": "co.ericrabil.mymodule",
    "main": "mymodule.js",
    "commands": {
        "directory": "Commands",
        "group": "Utilities"
    },
    "name": "EricRabil MyModule"
}
  1. Change the identifier, main and name field to your module info. Don't touch the commands field.
  2. Save and move on to number two.

2. Creating your main module file

Your main module file is the heart of your module. It is what will load any other files as well as do the initial tasks of your module.

  1. Create mymodule.js (or the new name of your main field in your module.json) in your module directory.
  2. Copy and paste this boilerplate into your main module file:
class MyModule {
    constructor(client) {
        this.client = client;
        this.meta = require('./module');
    }
}

module.exports = MyModule;
  1. As you did in the first part of the tutorial, change any fields to your liking.

In your constructor, you can do basically anything any other class would do. Just follow the standards for a good module.

3. Creating your commands (optional)

Modules also support commands, this way it is easy to plug-in/out groups of commands without having to manually disable each command.

  1. Create a Commands folder or whatever your commands.directory field is in your module meta file.
  2. Create a mymodulecommand.js file in your commands folder.
  3. Copy and paste this boiler plate into your newly created command file:
const Command = require("../../../Util/Command");

module.exports = new Command("mymodulecommand", "This is my module command lmao!", "[arg1] <arg2> etc.", ["mymodulecommandalias1", "mymodulecommandalias2"],
    (client, message, response, args) => {
        response.reply("This is my module command!", embed, true);
    }, [], false, true
);

You may have to adjust how the command constant is required. We will be converting any libraries/utilities into a DDUtil npm module so that it is easier to create modules.

A breakdown of the commands api is available here

A breakdown of the modules api is available here