Events Overview
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 = .();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 onceYou can check more information about bus creation in the Event Buses page.
What's next?
Last updated on
