Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
discord-xp
Advanced tools
A lightweight and easy to use economy framework for discord bots, uses MongoDB.
You can download it from npm:
npm i discord-xp
You can update to a newer version to receive updates using npm.
npm update discord-xp
27 May 2021 (v1.1.11) - Adding deleteGuild() method.
3 April 2021 (v1.1.11) - Adding TS typings.
25 February 2021 (v1.1.8) - Preventing further deprection warnings to be displayed, if you encounter any of these deprecation issues, update the module.
22 November 2020 (v1.1.7) WARNING: This semi-major version contains breaking changes in the way leaderboard computing function works.
fetchPosition
argument to the Levels.fetch
which will add the leaderboard rank as the position
property. Caution: Will be slower on larger servers.Levels.computeLeaderboard
is now asynchronous and can take in a third parameter called fetchUsers
which will fetch all users on the leaderboard. This parameter does not require additional Gateway Intents. Caution: Will be substantially slower if you do not have Guild_Members
intent and catch some users beforehand.xpFor
method to calculate xp required for a specific level./* xpFor Example */
const Levels = require("discord-xp");
// Returns the xp required to reach level 30.
var xpRequired = Levels.xpFor(30);
console.log(xpRequired); // Output: 90000
First things first, we include the module into the project.
const Levels = require("discord-xp");
After that, you need to provide a valid mongo database url, and set it. You can do so by:
Levels.setURL("mongodb://..."); // You only need to do this ONCE per process.
Examples can be found in /test
createUser
Creates an entry in database for that user if it doesnt exist.
Levels.createUser(<UserID - String>, <GuildID - String>);
Promise<Object>
deleteUser
If the entry exists, it deletes it from database.
Levels.deleteUser(<UserID - String>, <GuildID - String>);
Promise<Object>
deleteGuild
If the entry exists, it deletes it from database.
Levels.deleteGuild(<GuildID - String>);
Promise<Object>
appendXp
It adds a specified amount of xp to the current amount of xp for that user, in that guild. It re-calculates the level. It creates a new user with that amount of xp, if there is no entry for that user.
Levels.appendXp(<UserID - String>, <GuildID - String>, <Amount - Integer>);
Promise<Boolean>
appendLevel
It adds a specified amount of levels to current amount, re-calculates and sets the xp reqired to reach the new amount of levels.
Levels.appendLevel(<UserID - String>, <GuildID - String>, <Amount - Integer>);
Promise<Boolean/Object>
setXp
It sets the xp to a specified amount and re-calculates the level.
Levels.setXp(<UserID - String>, <GuildID - String>, <Amount - Integer>);
Promise<Boolean/Object>
setLevel
Calculates the xp required to reach a specified level and updates it.
Levels.setLevel(<UserID - String>, <GuildID - String>, <Amount - Integer>);
Promise<Boolean/Object>
fetch (Updated recently!)
Retrives selected entry from the database, if it exists.
Levels.fetch(<UserID - String>, <GuildID - String>, <FetchPosition - Boolean>);
Promise<Object>
subtractXp
It removes a specified amount of xp to the current amount of xp for that user, in that guild. It re-calculates the level.
Levels.subtractXp(<UserID - String>, <GuildID - String>, <Amount - Integer>);
Promise<Boolean/Object>
subtractLevel
It removes a specified amount of levels to current amount, re-calculates and sets the xp reqired to reach the new amount of levels.
Levels.subtractLevel(<UserID - String>, <GuildID - String>, <Amount - Number>);
Promise<Boolean/Object>
fetchLeaderboard
It gets a specified amount of entries from the database, ordered from higgest to lowest within the specified limit of entries.
Levels.fetchLeaderboard(<GuildID - String>, <Limit - Integer>);
Promise<Array [Objects]>
computeLeaderboard (Updated recently!)
It returns a new array of object that include level, xp, guild id, user id, leaderboard position, username and discriminator.
Levels.computeLeaderboard(<Client - Discord.js Client>, <Leaderboard - fetchLeaderboard output>, <fetchUsers - boolean, disabled by default>);
Promise<Array [Objects]>
xpFor
It returns a number that indicates amount of xp required to reach a level based on the input.
Levels.xpFor(<TargetLevel - Integer>);
Integer
FAQs
A lightweight and easy to use economy framework for discord bots, uses MongoDB.
The npm package discord-xp receives a total of 9 weekly downloads. As such, discord-xp popularity was classified as not popular.
We found that discord-xp demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.