Options
All
  • Public
  • Public/Protected
  • All
Menu

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:

const { Task } = require('@alexthemaster/moonlight');

module.exports = class extends Task {
    constructor(...args) {
        super(...args, {
            name: 'name', // defaults to the filename
            disabled: false, // defaults to false
            time: '* * * * *', // this can accept either a cron or a Date
        })
    }

    run() {

    }

    // This function runs when the bot is first started
    init() {

    }
}

or the following for TypeScript:

import { Task, MoonlightClient, BasePool } from '@alexthemaster/moonlight';

export default class extends Task {
    constructor(client: MoonlightClient, pool: BasePool<string, Task>) {
        super(client, pool, {
            name: 'name', // defaults to the filename
            disabled: false, // defaults to false
            time: '* * * * *', // this can accept either a cron or a Date
        })
    }

    public run() {

    }

    // This function runs when the bot is first started
    public init() {

    }
}
abstract

Hierarchy

Index

Constructors

constructor

Properties

Private _job

_job: CronJob | null = null

Readonly client

Optional Readonly description

description: undefined | string

The description of the piece

disabled

disabled: boolean

Whether or not this piece is disabled

name

name: string | undefined

The name of the piece

options

options: BasePieceOptions | undefined

Readonly pool

pool: BasePool<string, Task>

The pool this piece is part of

time

time: string | Date

Methods

Private _createJob

  • _createJob(): void

disable

  • disable(): void

enable

  • enable(): void

init

  • init(): void

reload

  • reload(): void

run

  • run(...arg: any[]): void

Generated using TypeDoc