Skip to content

No Events

As you might have noticed by now Lilybird does not have an events API and you might be questioning this decision so let’s discuss the motivation behind this.

The main motivation behind not having events is performance. Event emitters are really bad when it comes to high throughput and are really easy for the user to misuse them and cause memory leaks. To avoid these issues we went with the same approach that uws and, for that matter, bun use for their WebsocketServer: callbacks.

You might be wondering, “so how can I listen to events or even collect message components?“.

Let me answer that for you. Usually, it’s very unlikely that you need to listen to an event more than once. If you do find yourself in that situation, you can always create multiple functions and call them from the same listeners, like so::

1
import { createClient, Intents } from "lilybird"
2
3
function useInteraction1(interaction) {
4
console.log(interaction.token);
5
}
6
7
function useInteraction2(interaction) {
8
console.log(interaction.data);
9
}
10
11
await createClient({
12
token: process.env.TOKEN,
13
intents: [Intents.GUILDS],
14
listeners: {
15
interactionCreate: (interaction) => {
16
useInteraction1(interaction);
17
useInteraction2(interaction);
18
}
19
}
20
})

As for collecting message components, I’m currently working on an API for collectors that I will try to make as extensible as possible so this should not be an issue once Lilybird has its first stable release.