For the complete documentation index, see llms.txt. This page is also available as Markdown.

Events

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


1. Setting up the event file

  1. Copy the event template.

const event = require('../../../../main/discord/core/events/event.js');
const { Events } = require('discord.js');

module.exports = class startUp extends event {
  constructor(heart) {
    super(heart, { name: 'startUp', event: { discord: Events.ClientReady, bypassManager: false, dm: false, bypassRestrictions: true, permissionLevel: null } });
  }

  execute(client) {
    this.heart.core.console.log(this.heart.core.console.type.log, 'The bot is ready now :)');
  }
};
  1. Create a new event file inside your /plugins/<plugin_name>/src/events/ directory.

  2. The name of the file must follow the format <event_name>.js. Please note that in this case the event name does not match the Discord event. Try to use a unique event name.

Parameters

  • name: A unique identifier for the event.

  • discord: The corresponding discord.js event name.

  • bypassManager: Avoid setting this to true unless you are certain of the consequences.

  • dm: Applicable only for Discord.interactionCreate events. Determines whether the interaction should also fire in DMs.

  • bypassRestrictions: Must remain true.

  • permissionLevel: Applicable only for Discord.interactionCreate events. This works like the permission configuration. Set to null to allow everyone.

For custom events, the important value is event.discord. It must exactly match the emitted event name.


2. Event response

It is important to note that each event comes with its own parameters, which you receive in the method header. A full list of available events and their return values can be found in the Discord.js documentation.

Interaction events

To begin, let’s look at a code snippet that creates a button.

The corresponding event file:

Component interaction IDs are the unique identifiers for component interactions. They allow Athena to determine which event file should be executed and which configuration options should be applied. It is important that labels follow this format: iynx:athenabot:<interaction_name>:<additional_data>.

The <interaction_name> must match the event name you defined, not the discord.js event name.

As you may have noticed, the Discord.interactionCreate event includes an additional parameter that discord.js does not provide: interactionId. This parameter represents the interaction label, returned as an array. For example: ['iynx', 'athenabot', 'testButton', '<executor_id>', '<data>'].

If you want to restrict button access so only the user who ran the command can use it, add a simple check:


3. Additional information

Athena also provides custom embed builders for warnings, errors, and success messages. See the internal API documentation for more details.

Last updated