Handlers
This page explains how to create your own handlers for your AthenaBot plugin.
1. Setting up the handler file
Copy the handler template.
const handler = require('../../../../main/discord/core/handler/handler.js');
module.exports = class testHandler extends handler {
constructor(heart) {
super(heart, 'test');
this.api = '';
}
setAPI(url) {
if (!url) return false;
this.api = url;
return true;
}
getAPI() {
if (!url) return null;
return this.api;
}
};Create a new handler file inside your
/plugins/<plugin_name>/src/handler/directory.The name of the file must follow the format
<handler_name>.js.At the
load()function of your plugin’smain.jsfile, register the handler.
Parameters
'test': A unique identifier for the handler.
2. Working with handlers
Handlers are not mandatory, but they are very useful if multiple files require the same functions or access to the same temporary database. They can be imported throughout the bot, and you can access handlers provided by different plugins.
To do so, add the following snippet to your file:
In our case:
Athena provides over 20 custom handlers, ranging from cooldown, permission, and invite handlers to moderation, ticket, and Minecraft access. This allows you to integrate Athena’s features into your plugin easily. For example, you can hook into the moderation plugin to automatically warn a user on Discord for certain actions.
It is recommended to make use of the handlers Athena offers to keep your plugin consistent with the rest of the bot infrastructure.
Last updated