djs-simple-xp
v1.0.0-alpha.1
Published
The Discord XP System is a customizable, extensible system for managing XP, levels, and multipliers for users in a Discord bot. This system provides a structured approach to handle XP-related features in your Discord bot with support for different XP calc
Downloads
3
Readme
Discord XP System
The Discord XP System is a customizable, extensible system for managing XP, levels, and multipliers for users in a Discord bot. This system provides a structured approach to handle XP-related features in your Discord bot with support for different XP calculation methods and the ability to set multipliers for individual users or entire servers.
Table of Contents
Features
- Calculate XP and levels using various methods, including linear, exponential, logarithmic, or custom calculations.
- Set multipliers to adjust XP gains for individual users and entire servers.
- Seamless integration with Discord.js and MongoDB for data storage.
- Customizable configuration options to tailor the system to your needs.
- Event-driven architecture for easy integration into your Discord bot.
Getting Started
Installation
To get started, you'll need to install the discord-xp-system
package from npm:
npm install discord-xp-system
Usage
const { Client } = require('discord.js');
const { XpSystem } = require('discord-xp-system');
const client = new Client();
const xpSystem = new XpSystem({
initialXP: 100,
xpMode: 'per_user',
xpCalculation: 'linear',
mongoUri: 'mongodb://localhost:27017/xp-database',
defaultMultiplier: 1, // Default multiplier
});
client.login('YOUR_BOT_TOKEN');
client.on('message', (message) => {
if (message.content.startsWith('!addxp')) {
// Add XP to a user
const user = message.author;
const guild = message.guild;
const xpAmount = 100;
xpSystem.xp.addXp(user, guild, xpAmount);
}
});
Configuration
You can customize your XP system by configuring various options when creating an instance of XpSystem
. Here's what each configuration option does:
initialXP
: The initial XP when a user starts.xpMode
: XP mode (per user or per guild).xpCalculation
: XP calculation logic (linear, exponential, logarithmic, custom).customXpCalculation
: Custom XP calculation function (optional).mongoUri
: MongoDB URI for database connection.defaultMultiplier
: Default multiplier for XP gain.
XP Calculation
You can choose from several XP calculation methods:
- Linear: Linear progression logic.
- Exponential: Exponential progression logic.
- Logarithmic: Logarithmic progression logic.
- Custom: Provide your own XP calculation function.
Multipliers
The system supports multipliers to adjust XP gains during special events or promotions. You can set both user-specific and server-specific multipliers.
User-Specific Multipliers
You can set a user-specific multiplier to adjust XP gains for individual users. This is useful for providing special XP rates to specific users.
xpSystem.multipliers.setUserMultiplier(userId, multiplier);
Server-Specific Multipliers
Server-specific multipliers allow you to adjust XP gains for an entire server. This can be handy for events that affect all users in a server.
xpSystem.multipliers.setServerMultiplier(serverId, multiplier);
Database
The XP System uses MongoDB for data storage. Make sure to provide a valid MongoDB URI when configuring the system.
Examples
For more advanced usage and integration into your Discord bot, check out the examples provided in the examples/
directory of this package.
Contributing
Contributions are welcome! Feel free to open issues or pull requests on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Enjoy using the Discord XP System in your Discord bot! If you have any questions or encounter any issues, feel free to reach out for assistance.