-
Notifications
You must be signed in to change notification settings - Fork 1
Creating plugins🔌
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.
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.
- Create your module directory. In this example, it will be called "MyModule"
- 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"
}
- Change the
identifier
,main
andname
field to your module info. Don't touch the commands field. - Save and move on to number two.
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.
- Create
mymodule.js
(or the new name of yourmain
field in yourmodule.json
) in your module directory. - Copy and paste this boilerplate into your main module file:
class MyModule {
constructor(client) {
this.client = client;
this.meta = require('./module');
}
}
module.exports = MyModule;
- 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.
Modules also support commands, this way it is easy to plug-in/out groups of commands without having to manually disable each command.
- Create a
Commands
folder or whatever yourcommands.directory
field is in your module meta file. - Create a
mymodulecommand.js
file in your commands folder. - 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