Skip to content

Creating Modules

Andrew Graber edited this page Aug 14, 2020 · 2 revisions

The module system that ModBot provides lies at the heart of its systems. Each module can have its own set of commands, event handlers, notifications, and more. Modules are generally separated based on a specific application or purpose. For example, there is the 'Admin' module, which handles administrative actions in discord like managing servers, users, roles, etc. Another example would be the 'League of Legends' module which holds a subset of commands specific to the game.

Creating a new module is simple. First, you'll want to create a new directory inside the ModBot/modules/ folder, which will house all of the files for this module. In order for ModBot to be able to understand your module, you'll need to provide a file called 'bot_module.json' inside your module folder. This file handles all of the configuration for your module. An example bot_module.json is provided below:

ModBot/modules/<module_folder>/bot_module.json

{
    "name": "example",
    "display_name": "Example Module",
    "version": "1.0.0",
    "enabled": true,
    "commands_directory": "commands",
    "command_prefix": "/",
    "is_core": false,
    "event_handler": false
}
Option Description Valid Values
name The name of the module, used internally. Max 50 characters. [a-z]+
display_name The formatted name of the module. This is displayed to users, and can contain whatever characters you want. Any String
version The version of the module Any String
enabled Controls the module being enabled for the entire bot. If set to false, the module will not load even if a specific server has it enabled. `true
commands_directory The name of the directory command files are placed in, relative to the module folder. Name of directory (no ending '/')
command_prefix The prefix that will be used for commands in this module. It can be any character or sequence of characters, as long as there are no spaces. Any sequence of characters (ex: "/", "!", "<asdf^-")
is_core Determines whether this module is a 'Core Module' (more info below) true|false
event_handler Gives the location of the JavaScript file that handles events for this module. If you do not require an event handler for your module, set this to false. Any string, or false

Once you've set up your bot_module.json, you'll need to create the directory where your command files will be stored. This will be named whatever you put in your bot_module.json, but generally we just use commands/.

Each *.js file placed inside this folder will be recognized by ModBot on startup (or if /reload is run) as a separate command. See Creating Commands to learn how to get started making your own bot commands.

//TODO put a link to Creating Commands

Clone this wiki locally