Getting Started

Listening to Events

This section is relevant only for gateway-based applications.
If your bot is built exclusively as an HTTP application, you can skip this section.

Updating Seyfert's Configuration

Before starting this section, you need to update the seyfert.config.mjs file to specify the location of the event files for Seyfert.

seyfert.config.mjs
import {  } from 'seyfert';
 
export default .({
    : .. ?? '',
    : ['Guilds'],
    : {
        : 'dist',
        : 'commands',
        : 'events' // - src/events will be our folder for events
    }
});

Listening to Events

Each event file must export the createEvent function as the default export so Seyfert can load it.
The createEvent function takes an object with two properties: data and run.

Let's listen to the botReady event as the first example:

src/events/botReady.ts
import {  } from 'seyfert';
 
export default ({
  // botReady is triggered when all shards and servers are ready.
  // `once` ensures the event runs only once.
  : { : true, : 'botReady' },
  (, ) {
 
    //  We can use client.logger to display messages in the console.
    ..(`${.} is ready`);
 
  }
})

As a second example, let's look at the guildDelete event emitted by Discord when a bot is removed from a server or the server is deleted:

src/events/guildDelete.ts
import {  } from 'seyfert';
 
export default ({
  : { : 'guildDelete' },
  (, ) {
    // unguild is the server from which the bot was removed or deleted.
    // It is also possible that the server was simply deleted.
    if (.) return;
 
    ..(`I was removed from: ${.}`);
  }
})

After completing these steps, your project structure should look like this:

src
commands
events
index.ts
package.json
seyfert.config.mjs
tsconfig.json
.env

On this page