> For the complete documentation index, see [llms.txt](https://docs.iynxdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.iynxdev.com/addon-api/getting-started/handlers.md).

# Handlers

This page explains how to create your own handlers for your AthenaBot plugin.

***

## 1. Setting up the handler file

1. Copy the handler template.

```js
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;
  }
};
```

2. Create a new handler file inside your `/plugins/<plugin_name>/src/handler/` directory.
3. The name of the file must follow the format `<handler_name>.js`.
4. At the `load()` function of your plugin’s `main.js` file, register the handler.

```js
load() {
  const testHandler = require('./src/handler/<handler_name>.js');
  this.heart.core.discord.core.handler.manager.register(new testHandler(this.heart));
}
```

### 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:

```js
const handler = this.heart.core.discord.core.handler.manager.get('<handler_name>');
```

In our case:

```js
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 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.

```js
const mod = this.heart.core.discord.core.handler.manager.get('mod');
await mod.warn(interaction.guild, user, interaction.user, null, reason);
```

> It is recommended to make use of the handlers Athena offers to keep your plugin consistent with the rest of the bot infrastructure.
