Registers a task to be ran at fixed times (UTC) or intervals. Each execution of the task is an independent event execution context with it's own limits and context.
Cron strings are a list of time selectors separated by space. The format can be seen below:
┌───── Second (0-59)
│ ┌───── Minute (0-59 or *)
│ │ ┌───── Hour (0-23 or *)
│ │ │ ┌───── Day of Month (1-31 or *)
│ │ │ │ ┌───── Month (1-12, Jan-Dec, or *)
│ │ │ │ │ ┌───── Day of Week (1-7, Mon-Sun, or *)
│ │ │ │ │ │ ┌───── Year (optional, default: *)
│ │ │ │ │ │ │
* * * * * * *
Time fields may specify ranges, lists or intervals w/ offsets.
Ranges: Every hour from 11AM through 4PM (UTC) on Monday thru Friday: 0 0 11-16 * * Mon-Fri *
Lists: Every Monday, Wednesday, and Friday at 12PM (UTC): 0 0 12 * * Mon,Wed,Fri *
Intervals: Every 5th minute, starting from minute 0: 0 0/5 * * * * *
Note: The current minimum interval Pylon crons can run at are once every 5 minutes. You may schedule up to 5 cron handlers.
Example A cron that updates a voice channel's name every 10 minutes with the server's member count.
// Set a constant voice channel id to use for this task.
const VOICE_CHANNEL_ID = '524396721154176388430416';
// Register a cron task
pylon.tasks.cron('update_member_count', '0 0/10 * * * * *', async () => {
const channel = await discord.getGuildVoiceChannel(VOICE_CHANNEL_ID);
if (!channel) {
return;
}
const guild = await discord.getGuild(channel.guildId);
if (!guild) {
return;
}
// Update the voice channel's name with the server's member count.
await channel.edit({
name: `${guild.memberCount.toLocaleString()} Members`
});
});
A unique identifier for this task. Must be alphanumeric including -
, _
, and .
.
A valid cron string for this task. See the docs for more info.
The event handler to call when the cron event fires.
Generated using TypeDoc
Tasks allow you to register your own event handlers to be triggered at specific intervals or times.
Tasks may not be registered at runtime (within event handler scopes). They must be registered at the root of your script. You must provide a unique task name for each task you register.
Task event handlers are subject to the same limits of standard event handlers.
See pylon.tasks.cron.