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

// First importing the class
const Plugin = require("djs-command-control");

// Creating our plugin with a unique name
const plugin = new Plugin("unique-name")

// What must out plugin do when it initializes
plugin.initialize = (djsCommandControl, ctx) => {
    // Let's create a new variable in the Commands Class
    ctx.ourNewVariable = "Hello Word";
    
    // Let's add a custom variable to out global djsCommandControl object inside client
    djsCommandControl.ourCustomVariable = "Duck";
    
    // Let's add another category to the command handler
    // This category is now available for any command we want to add to it
    ctx.categories.push({ name: "egg", title: "Uninstatiated Chicken"});
    
    // Now let's add a fail condition, if pond === missing
    // returning false will make sure the plugin is not loaded
    if (pond === "missing") return false;
    // Returning our modified djsCommandControl Objects tells
    // the commands class that we have finished what we want
    // and it can load the plugin now
    else return djsCommandControl;
}

// Let's add a bundled command, let's say it was
// already required and is in a variable called customCommand of type `Command`
plugin.addBundledCommand(customCommand);

// Now we can either export the plugin instance to import it later,
// or we can directly add it to the commands object.
// For this example I add it to the command object
commands.addPlugin(plugin)

Last updated