Aller au contenu
Sur cette page

`XpEvents.on()`

Ce contenu n’est pas encore disponible dans votre langue.

Register callback handlers for logs and level events.

All callback properties are optional, and each callback can return either void or Promise<void>.

levelUp and levelDown are emitted by addXP(), removeXP(), setXP(), addLevel(), removeLevel(), and setLevel() whenever a user’s level changes.

Parameter Type Required Description
XpEventCallback XpEventCallback ✅ The callback to run when the event is emitted.
const { XpEvents } = require("simply-xp");
XpEvents.on({
debug: (xpFunction, message) => {
// Handle debug event
},
error: (xpFunction, message) => {
// Handle error event
},
info: (xpFunction, message) => {
// Handle info event
},
custom: (message) => {
// Handle your own custom event payloads
},
levelDown: (data, lostRoles) => {
// Handle levelDown event
},
levelUp: (data, newRoles) => {
// Handle levelUp event
},
warn: (xpFunction, message) => {
// Handle warn event
},
});

Register callbacks without replacing the ones already registered.

XpEvents.on() holds a single callback object — calling it again replaces whatever was there before, including handlers registered by a plugin or by another part of your project. XpEvents.add() appends instead, so any number of listeners can receive the same events.

Parameter Type Required Description
XpEventCallback XpEventCallback ✅ The callbacks to run when the events are emitted.
  • () => void - Call it to remove these callbacks again.
  • XpFatal - If the callbacks argument is not an object.
const { XpEvents } = require("simply-xp");
const removeListener = XpEvents.add({
levelUp: (data, newRoles) => {
// Runs alongside every other registered listener
},
});
// Later, when you no longer need it:
removeListener();