ItsMyStudio

Events

Create addon events, control execution order, and understand how events relate to script triggers.

Support

Use events/ for Discord gateway handlers and runtime event hooks.

What it is

Use this folder when the addon should react to a Discord event such as:

  • MessageCreate
  • InteractionCreate
  • GuildMemberAdd

Where to create it

messageCreate.ts
interactionCreate.ts

Create one file per event handler.

What it adds

This folder adds automatic behavior to the bot.

Instead of waiting for a user to call a slash command, the addon can react when Discord emits an event.

How to create it

Rules:

  • each file should export one default class
  • that class must extend Event<TAddon>
  • name should be a Discord Events.* value
  • execute() arguments must match that Discord event

Base event API

Prop

Type

Example

import { Event, Events } from '@itsmybot';
import { Message } from 'discord.js';
import MyAddon from '..';

export default class MessageCreateEvent extends Event<MyAddon> {
  name = Events.MessageCreate;
  priority = 3;

  async execute(message: Message) {
    this.logger.debug(message.content);
  }
}

How priority works

If multiple event classes listen to the same name, the executor sorts them by priority.

  • lower number = earlier execution
  • same number = execution order depends on registration order
  • cancelEvent() stops later handlers for that same event cycle

once and every

Use once when the event should only run one time after startup.

Use every when the event is frequent but your addon only needs periodic processing.

Example:

every = 10;

That means the handler only runs once every ten received events.

Event names and script triggers

Use an Event when addon code itself should react to runtime activity.

Use a trigger when YAML scripts should react to it.

Continue with Triggers for the developer-facing view of script trigger emission.

On this page