Schedules
This page explains how to create your own schedules for your AthenaBot plugin.
1. Setting up the schedule file
Copy the schedule template.
const scheduledTask = require('../../../../main/discord/core/schedule/schedule.js');
module.exports = class loop extends scheduledTask {
constructor(heart) {
super(heart, 'loop', { repeat: true, interval: 60000 });
}
execute() {
this.heart.core.console.log(this.heart.core.console.type.log, '60 seconds have passed since the last time :-:');
}
};Create a new schedule file inside your
/plugins/<plugin_name>/src/schedules/directory.The name of the file must follow the format
<schedule_name>.js.
Parameters
'loop': A unique identifier for the schedule.repeat: Defines whether the file should be executed repeatedly every
<interval>milliseconds, or only once after<interval>milliseconds.interval: The time in milliseconds between each execution.
2. Schedule response
Schedules are used to handle tasks that occur repeatedly. A common example is unmutes.
When a user is muted, the mute duration and punishment date are stored in the user database. The bot then loads all documents of currently muted users and, at each interval check, determines whether the mute has expired. If so, it automatically executes the unmute function.
For an example, see the unmute schedule from Athena’s source code:
3. Additional information
Intervals are not executed immediately. Once the time until the next execution has passed, the schedule is pushed to Athena’s schedule queue, so it may take up to 20 additional seconds for your schedule to run.
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