Handling Events
To handle client events you must require/import the Maker class and Event decorator from erine and then extend the Maker class and put the event inside using the Event decorator.
Examples
Ready Event
const { Event, Maker } = require("erine");
class Listeners extends Maker {
@Event
async ready(context) {
console.log("Successfully logged in as: ".concat(this.bot.user.username));
}
}
module.exports = { data: Listeners }; // Important to export the class as "data".
Error
Taking advantage of the Oceanic.js error event, we can handle Custom Errors from our custom Context class.
const { Errors, Event, Maker } = require("erine");
class Listeners extends Maker {
@Event
async error(err) {
if (err instanceof Errors.MissingRequiredParam) {
await err.ctx.send("Missing required param ".concat(`"#${err.param.name}"`));
} else console.log(err);
}
}
module.exports = { data: Listeners }; // Important to export the class as "data".
Notes
- The function name must be the event name to be handled. If the event name = "messageCreate", then
async messageCreate(message) {}
. - You can access to the client properties by using
this.bot
.