Extending
This page will cover how to extend the library to fit your needs

Overview

This module can be extended by a plugin system. A valid plugin is a plugin the exports and instance of Plugin. It is registered by passing the exported instance to Commands.prototype.addPlugin

Example Plugin:

This is an example plugin that does the very basics
1
// First importing the class
2
const Plugin = require("djs-command-control");
3
4
// Creating our plugin with a unique name
5
const plugin = new Plugin("unique-name")
6
7
// What must out plugin do when it initializes
8
plugin.initialize = (djsCommandControl, ctx) => {
9
// Let's create a new variable in the Commands Class
10
ctx.ourNewVariable = "Hello Word";
11
12
// Let's add a custom variable to out global djsCommandControl object inside client
13
djsCommandControl.ourCustomVariable = "Duck";
14
15
// Let's add another category to the command handler
16
// This category is now available for any command we want to add to it
17
ctx.categories.push({ name: "egg", title: "Uninstatiated Chicken"});
18
19
// Now let's add a fail condition, if pond === missing
20
// returning false will make sure the plugin is not loaded
21
if (pond === "missing") return false;
22
// Returning our modified djsCommandControl Objects tells
23
// the commands class that we have finished what we want
24
// and it can load the plugin now
25
else return djsCommandControl;
26
}
27
28
// Let's add a bundled command, let's say it was
29
// already required and is in a variable called customCommand of type `Command`
30
plugin.addBundledCommand(customCommand);
31
32
// Now we can either export the plugin instance to import it later,
33
// or we can directly add it to the commands object.
34
// For this example I add it to the command object
35
commands.addPlugin(plugin)
Copied!
Last modified 6mo ago
Copy link