trixxy-leveling
v1.0.0
Published
A Discord leveling system with image generation for Trixxy projects.
Downloads
9
Maintainers
Readme
trixxy-leveling
A powerful and customizable Discord leveling system with image generation capabilities, built for Trixxy projects.
Features
- Automatic XP Gain: Users gain XP by sending messages.
- Customizable Leveling Formula: Adjust how much XP is needed for each level.
- Dynamic Level Cards: Generate beautiful level cards with user avatars, XP, and level progress.
- Customizable Messages: Set your own level-up messages.
- Flexible Configuration: Easily change background, font color, and progress bar color.
Installation
npm install trixxy-levelingUsage
Basic Setup
const { Client, GatewayIntentBits } = require('discord.js');
const TrixxyLeveling = require('trixxy-leveling');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
const leveling = new TrixxyLeveling({
client: client, // Your Discord.js client
background: 'https://example.com/your-custom-background.png', // Optional: URL to a custom background image
fontColor: '#FFD700', // Optional: Hex color for text
progressBarColor: '#00FFFF', // Optional: Hex color for the progress bar
levelUpMessage: 'Well done, {user}! You've reached level {level}!', // Optional: Custom level up message
xpPerMessage: 15, // Optional: XP gained per message (default is 10)
levelFormula: (level) => 10 * Math.pow(level, 2) + 100 * level + 200, // Optional: Custom XP formula
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.login('YOUR_BOT_TOKEN');
// Example command to show a user's level card
client.on('messageCreate', async message => {
if (message.author.bot) return;
if (message.content === '!level') {
const userData = leveling.getUserData(message.author.id, message.guild.id);
const attachment = await leveling.generateLevelCard(message.author, userData.xp, userData.level);
message.channel.send({ files: [attachment] });
}
});TrixxyLeveling Class
Constructor Options
client(required): YourDiscord.jsclient instance. Used to listen formessageCreateevents.background(optional):StringURL to a custom background image for the level card. Default is a placeholder image.fontColor(optional):StringHex color code for the text on the level card. Default is#ffffff.progressBarColor(optional):StringHex color code for the progress bar on the level card. Default is#00ff00.levelUpMessage(optional):StringCustom message sent when a user levels up. Supports{user}and{level}placeholders. Default is'Congratulations, {user}! You leveled up to level {level}!'.xpPerMessage(optional):NumberAmount of XP a user gains per message. Default is10.levelFormula(optional):FunctionA function that takes the currentlevelas an argument and returns the required XP for that level. Default is(level) => 5 * Math.pow(level, 2) + 50 * level + 100.
Methods
handleMessage(message): (Internal) Processes incoming messages to award XP and check for level-ups. Automatically called ifclientis provided in the constructor.generateLevelCard(user, currentXp, currentLevel):Async FunctionGenerates a level card image for the specified user. Returns aDiscord.js AttachmentBuilder.user: ADiscord.js Userobject.currentXp:NumberThe user's current XP.currentLevel:NumberThe user's current level.
getUserData(userId, guildId): Returns an object{ xp: Number, level: Number }for the specified user and guild. If no data exists, returns{ xp: 0, level: 0 }.setUserData(userId, guildId, data): Sets the XP and level data for a specific user in a guild.
Requirements
- Node.js v16.6.0 or higher
discord.jsv14 or highercanvaslibrary requires some system dependencies. Please refer to the canvas documentation for installation instructions for your operating system.
Contributing
Feel free to open issues or submit pull requests.
License
This project is licensed under the MIT License.
