A task is a piece of code that runs at a given time or periodically (using cron).
To create a cron, you can head over to crontab.guru - we also support the non-standards! (@yearly, @annually, @monthly, @weekly, @daily and @hourly)
To get started with tasks, just add a file in your tasks folder and use the following example for JavaScript:
const { Task } = require('@alexthemaster/moonlight');module.exports = classextendsTask {constructor(...args) {super(...args, {name:'name', // defaults to the filenamedisabled:false, // defaults to falsetime:'* * * * *', // this can accept either a cron or a Date }) }run() { }// This function runs when the bot is first startedinit() { }}
or the following for TypeScript:
import { Task, MoonlightClient, BasePool } from'@alexthemaster/moonlight';exportdefaultclassextendsTask {constructor(client: MoonlightClient, pool: BasePool<string, Task>) {super(client, pool, {name:'name', // defaults to the filenamedisabled:false, // defaults to falsetime:'* * * * *', // this can accept either a cron or a Date }) }publicrun() { }// This function runs when the bot is first startedpublicinit() { }}
Creating tasks
A task is a piece of code that runs at a given time or periodically (using cron).
To create a cron, you can head over to crontab.guru - we also support the non-standards! (@yearly, @annually, @monthly, @weekly, @daily and @hourly)
To get started with tasks, just add a file in your
tasks
folder and use the following example for JavaScript:or the following for TypeScript: