Events
The event component wraps the discord.js’ built in events so you should be able to hit the ground running. There is also complete type safety so your editor will be able to provide helpful hints! As an example let’s create an event that reacts when your bot is online and ready:
Handling Events
When an event is emitted, it’s handler function (run
) recieves specific ordered arguments. The first argument is always the event context (which includes the client
and props
). The remaining arguments correspond to the event type, as defined in the Discord.js docs.
Let’s look at the channelUpdate
event as an example. According to the Discord.js Client documentation, this event provides two arguments: oldChannel
and newChannel
.
We can then combine that to create our event handler:
Event Context
We pass the “event context” as the first argument to the run
fn, which is an object that includes:
client
- this is your JellyCommands clientprops
- this is a shortcut to yourclient.props
For example, let’s destructure these from the context of the above example:
Running only once
You can configure an event handler to run only once
, then automatically remove itself. This once
option is specific to each individual component - other event components listening for the same event will continue to run normally.