The LevelManager allows you to modify the way it calculates the XP required to level up. The default calculation is as follows:
function xpFunction(level, xp) {
return level * this.maxXpToLevelUp;
}
The xpFunction takes the current level and current XP as parameters, and it is expected to return the XP required to level up.
The this
inside the xpFunction refers to the LevelManager, so you can access its properties.
If you want to modify the function, you can do so from the options of the LevelManager:
const { LevelManager } = require('discord-xplus')
const manager = new LevelManager({
xpFunction: function (level, xp) {
return level * this.maxXpToLevelUp;
}
})
IMPORTANT: Do not use arrow functions, as the this
does not refer to the LevelManager due to how JavaScript works.