Skip to content

Events

Events are how your bot reacts to things happening on Discord (e.g., a message being sent, a user joining, or the bot starting up).

Creating an Event

Each event handler is a separate file that exports an object matching the Event<T> interface.

typescript
import { Events } from 'discord.js';
import type { Event } from '@thezombiepl/zombieclient/interfaces';

export default {
    name: Events.ClientReady,
    once: false,
    
    async execute(client, readyClient) {
        console.log(`Bot is ready as ${readyClient.user.tag}`);
    },
} satisfies Event<'clientReady'>;

Important: Always use the Events enum from discord.js (e.g., Events.ClientReady, Events.MessageCreate) instead of raw strings ('ready'). This ensures compatibility with discord.js v15.

Error Boundaries

The ZombieClient EventLoader automatically wraps every single event handler in a try/catch block.

If your event handler throws a synchronous error, or returns a rejected Promise (asynchronous error), the EventLoader will catch it, prevent the bot from crashing, and safely log the error with a [EVENT EXECUTE ERROR] prefix.

You don't need to wrap your entire execute function in try/catch blocks just to keep your bot alive.

Wszelkie prawa zastrzeżone.