XpEvents
On this page
`XpEvents.on()`
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.
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
| XpEventCallback | XpEventCallback | ✅ | The callback to run when the event is emitted. |
Examples
Section titled “Examples”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 },});XpEvents.add()
Section titled “XpEvents.add()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
| XpEventCallback | XpEventCallback | ✅ | The callbacks to run when the events are emitted. |
Returns
Section titled “Returns”() => void- Call it to remove these callbacks again.
Throws
Section titled “Throws”XpFatal- If the callbacks argument is not an object.
Example
Section titled “Example”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();