Options
All
  • Public
  • Public/Protected
  • All
Menu

Creating events

⚠ Note: if you want to run something AFTER the bot is ready, please use the moonlightReady event instead of simply using ready

An event is arguably one of the most important things your bot will listen to.

To get started with events, just add a file in your events folder and use the following example for JavaScript:

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

module.exports = class extends Event {
    constructor(...args) {
        super(...args, {
            name: 'name', // defaults to the filename
            disabled: false, // defaults to false
            event: 'ready', // the event this file listens to (autocomplete is available and all!)
            once: false // whether or not to only listen to the event above once, defaults to false
        })
    }

    // Any arguments the event receives will be passed to the run function (for example `message` for the message event)
    run() {

    }

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

    }
}

or the following for TypeScript:

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

export default class extends Event {
    constructor(client: MoonlightClient, pool: BasePool<string, Event>) {
        super(client, pool, {
            name: 'name', // defaults to the filename
            disabled: false, // defaults to false
            event: 'ready', // the event this file listens to (autocomplete is available and all!)
            once: false // whether or not to only listen to the event above once, defaults to false
        })
    }

    // Any arguments the event receives will be passed to the run function (for example `message` for the message event)
    public run() {

    }

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

    }
}
abstract

Hierarchy

Index

Constructors

constructor

Properties

Readonly client

Optional Readonly description

description: undefined | string

The description of the piece

disabled

disabled: boolean

Whether or not this piece is disabled

Readonly event

event: keyof ClientEvents

The event to listen to

name

name: string | undefined

The name of the piece

Readonly once

once: boolean

Whether or not to run this event only once

options

options: BasePieceOptions | undefined

Readonly pool

pool: BasePool<string, Event>

The pool this piece is part of

Methods

disable

  • disable(): void

enable

  • enable(): void

init

  • init(): void

reload

  • reload(): void

run

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

Generated using TypeDoc