Listen to an event
Esta página aún no está disponible en tu idioma.
Events are used to listen for events emitted by multiple sources like discord client or zumito framework. This allows you to execute code when a specific event is emitted.
To start listening to an event, you just need to run the following command:
It will ask you for the name of the event, and the module where you want to create it.
After that, it will create a file in the src/modules/<module>/events
folder with the name of the event.
The file will contain the following code:
To start defining the event, you need to define the once
property. This property defines if the event will be executed only once or every time the event is emitted.
Now, let’s define an example event for the interactionCreate
event.
First, we will define the once
property to false
cause we want to execute the event every time the event is emitted:
Next, we will define the source
property to discord
cause we want to listen to a discord event. for other use cases we can listen to other sources like framework
:
Now, we need to define the execute
function. This function will be executed every time the event is emitted.
The execute
function receives an EventParameters
object, which contains the following properties:
message
- The message that triggered the event. Only available formessageCreate
event.interaction
- The interaction that triggered the event. Only available forinteractionCreate
event.client
- The Discord.js client.framework
- The Zumito Framework instance.
Now, let’s define the event code: