1.3.1 • Published 3 years ago
discordjs-xp v1.3.1
discordjs-xp
This is a simple and unique package that uses MongoDB and lets you easily set up a levelling system for your discord bot. It includes many in-built features such as creating a user schema to the database and also includes fetching and deleting. Unlike many other packages, this package includes easy to follow properties and methods so that you know where you can find them.
Note
Node.js version 16.9.0 or higher is required for this package to function as intended
Features
- 100% Promise-based package
- Easy to find properties and methods
- Included type declarations for TypeScript developers
Examples
Import the discordjs-xp package:
const DiscordXP = require("discordjs-xp"); // For CommonJS
import DiscordXP from "discordjs-xp"; // For ESM
Initialise the discordjs-xp package:
const xpClient = new DiscordXP("MongoDB URL"); // Create a new discordjs-xp instance
More examples:
// Create a new user
xpClient.users.create({ guildId: "Guild ID", userId: "User ID" }).then(async (user) => {
// When a user is created, the default level is 1 while the default XP is 0
await user.xp.add(10); // Add 10 XP to the user
await user.xp.subtract(10); // Subtract 10 XP from the user
await user.levels.add(1); // Increase the users level by 1
await user.levels.subtract(1); // Decrease the users level by 1
});
// Fetch an existing user from the database
xpClient.users.fetch({ guildId: "Guild ID", userId: "User ID" }).then(async (user) => {
await user.xp.add(10); // Add 10 XP to the user
await user.xp.subtract(10); // Subtract 10 XP from the user
await user.levels.add(1); // Increase the users level by 1
await user.levels.subtract(1); // Decrease the users level by 1
});
// Delete a user
xpClient.users.delete({ guildId: "Guild ID", userId: "User ID" });
xpClient.users.fetch({ guildId: "Guild ID", userId: "User ID" }).then(async (user) => await user.delete());
xpClient.users.create({ guildId: "Guild ID", userId: "User ID" }).then(async (user) => await user.delete());
Guild Property Examples
xpClient.guilds.fetchLeaderboard({ guildId: "Guild ID", limit: 100 });
xpClient.guilds.delete("Guild ID");
Support
If you encounter any problems with this system hop on into my discord and I will gladly try and fix your issue
Discord: https://discord.gg/RCUcSNTNrT