Repository navigation
Creating Handlers
This page explains how to create your own handlers for your AthenaBot plugin.
- 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 within your
/plugins/<plugin_name>/src/handler/directory. - The name of the file must follow this format:
<handler_name>.js - At the
load()function of your plugin'smain.jsfile you must register the handler.
load() {
const testHandler = require('./src/handler/<handler_name>.js');
this.heart.core.discord.core.handler.manager.register(new testHandler(this.heart));
/* Your code */
}- <'test'>: A unique identifier for the handler.
ㅤ
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 easily imported throughout the entire bot and you can access and use handlers provided by different plugins. To do so add following code snippet to your file:
const handler = this.heart.core.discord.core.handler.manager.get('<handler_name>');In our case:
const testHandler = this.heart.core.discord.core.handler.manager.get('test');
testHandler.setAPI('https://google.com/');
const testAPI = testHandler.getAPI();
console.log(testAPI); // Returns https://google.com/Athena provides over 20 custom handlers, ranging from cooldown, permission, and invite handlers to moderation, ticket, and Minecraft access.
This allows you, as a developer, to easily integrate Athena's features into your plugin. For example, you can hook into the moderation plugin to automatically warn a user on Discord for certain actions. Athena will then handle the warning process itself.
const mod = this.heart.core.discord.core.handler.manager.get('mod');
await mod.warn(interaction.guild, user, interaction.user, null, reason);To ensure consistency and maintain the continuity of the bot’s infrastructure, it is recommended to make use of the handlers that Athena offers.
AthenaBot Developer Documentation