Skip to main content
Version: 2.3

Custom Events

The service in charge of the events is the EventManager service.

Usage

Registering

In order to register an event, use the @OnCustom() decorator like this:

import { OnCustom } from '@/decorators'

export class YourEventHandler {

@OnCustom('myCustomEvent')
handleMyCustomEvent() {

console.log('I handled my custom event!')
}
}

It should be placed under the src/events/custom/ folder.

Emitting

In order to emit an event, use the emit() method on any injected instance of EventManager:

import { Service } from '@/decorators'
import { EventManager } from '@/services'

@Service()
export class YourService {

constructor(
private eventManager: EventManager
) {}

doSomething() {

this.eventManager.emit('myCustomEvent')
}
}

Parameters

Here is a simple example that demonstrates how to pass parameters to an event:

import { OnCustom } from '@/decorators'

export class YourEventHandler {

@OnCustom('myCustomEvent')
handleMyCustomEvent(x: number, name: string) {

for (let i = 0; i < x; i++) {
console.log(`Hello ${name}!`)
}
}
}
import { Service } from '@/decorators'
import { EventManager } from '@/services'

@Service()
export class YourService {

constructor(
private eventManager: EventManager
) {}

doSomething() {

this.eventManager.emit('myCustomEvent', 3, 'John Doe')
}
}

Built-in custom events

Event nameDescriptionLocation
templateReadyEmitted once the application has fully started (including api server, bot ready, etc)src/events/custom/templateReady.ts
simpleCommandCreateEmitted on simple interaction commandsrc/events/custom/simpleCommadCreate.ts