Skip to Content
nyx logonyx guide

Events Overview

Reading time:1 min read

The event system in nyx is powered by EventBuses. These are objects that store and notify their EventSubscribers when an event is called either internally or from another source.

You can see them as a more batteries-included way of handling events than using the native Node.js EventEmitter.

HTTP bots (@nyx-discord/http) have no gateway connection, so their client only emits InteractionCreate, plus webhook events if you set them up. Subscribers to other client events never fire.

Quick example

import { , type  } from '@nyx-discord/djs';
import { , type  } from 'discord.js';

class  extends <typeof .> {
  protected readonly  = .;

  public async (: , : ) {
    .(`Interaction created: ${.}`);
  }
}

await .(new ());

That's it! Your bot will now log every interaction.

Client Bus

The client is wrapped under an event bus, which you can get:

const bus = .();
const bus: EventBus<ClientEvents>

And you can directly subscribe to it:

await .(new ());
// Equivalent to:
await .().(new ());

Custom buses

You can create and directly use any bus you want:

const  = .<>(); // Waits for its subscribers to finish, with a timeout
const  = .<>(); // Executes a pool of subscribers at once

You can check more information about bus creation in the Event Buses page.

What's next?

Click on each card to go to its page.
Edit on GitHub

Last updated on

On this page