Events
This page explains how to create your own event listeners for your AthenaBot plugin.
1. Setting up the event file
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 :)');
}
};Create a new event file inside your
/plugins/<plugin_name>/src/events/directory.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.jsevent name.bypassManager: Avoid setting this to
trueunless you are certain of the consequences.dm: Applicable only for
Discord.interactionCreateevents. Determines whether the interaction should also fire in DMs.bypassRestrictions: Must remain
true.permissionLevel: Applicable only for
Discord.interactionCreateevents. This works like the permission configuration. Set tonullto 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 thediscord.jsevent 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 provides a custom error logging system that is deeply integrated into the framework. Do not throw errors directly. Instead, catch them and handle them with Athena’s error interface.
Last updated