Module Development
Overview
Section titled “Overview”By developing your own modules you are able to add custom features to your discord bot with ease.
For high-end developers who want to share their creations, it’s your lucky day! With 0xBot you can share your modules or even sell it, but you must follow the 0xBot Module developmment guidelines later on this page.
How does the bot load modules
Section titled “How does the bot load modules”The bot, has 2 module loading procceses.
- Module intializing. In this stage the bot goes module by module finding their metadata.json, which conatins most of the module’s data. This contains also the index file, wich must contain and export a
async function run()
, that will be executed once when the module is loaded. Here you are able to get some values, trhough the module api provided as an argument to the function.
export async function run(moduleApi) { // Any code here will be ran once when the bot loads the module}
- Command and events loading. After running the
run
function of each module, the bot will go, again trhough all the commands of each module, registering the command to the discord api, and then through the module’s events.
Module example structure.
Section titled “Module example structure.”modules └── example ├── commands │ └── exampleCommand.js ├── events │ └── exampleEvent.js ├── index.js ├── config.json └── metadata.json
This is the default structure of a module.
metadata.json
Section titled “metadata.json”The metadata.json contains the main information of the bot, such as the author
, name
, version
or mainfile
.
{ "name": "example", "version": "0", "author": "jallox", "main": "index.js"}
index.js
(main)
Section titled “index.js (main)”This file can be named as index.js
, main.js
, etc. It contains the run
function, wich will be called once when starting the module
export async function run(moduleApi) { // Any code here will be ran once when the bot loads the module}
/commands/
Section titled “/commands/”The bot will only read commands if they are on this directory. You can use any method in the SlashCommandBuilder
. Refer to the DiscordJS guide for more information.
This is the default command structure
import { SlashCommandBuilder } from 'discord.js';
export default { data: new SlashCommandBuilder() .setName('ping') .setDescription('Responds with pong'), //You can add here as many options as you want async execute(interaction, client) { // Command goes here interaction.reply("Pong!"); },};
/events/
Section titled “/events/”The bot will only read events if they are on this directory. This bot accepts any DiscordJS event
This is a default event structure
import { Events } from "discord.js";
export default { name: Events.MessageCreate, async execute(message, client) { // Here goes the command message.reply("I responded your comment!"); },};