For my discord bot, im trying to create a full leveling system. I want it to kind of be like mee6 leveling where you can see a leaderboard though a command, see your rank, and stuff like that. I’ve gone through a bunch of stuff about leveling but none seem to work for me. Can someone help me out with making a leveling system?
EDIT: Everyone who helped with this, thank you. Sorry if I sounded stupid and stuff, I was a really young developer and didn’t know much. Now I know a lot more and am able to do stuff like this lol.
I would recommend looking in to a type of database that could store user information. This way, when a user chats, that could be logged into the database as points.
Like RiversideRocks said, you need first a database.
1 - Choose a kind of database
If you will only need a database for this simple maybe you can check better-sqlite3 or db.quick
2 - Make the engine for xp points
When the bot get a message, you will have to add the xp points to the user who send the message. But you will have to separate:
userId
userName
guildId
xpPoints
So the user only gain xp when talks in a particular guild
3 - Make a level table or function
This is an example you can do it better
var constant = 3/2;
function calcLevel(xpPoints) {
level = constant * Math.floor(Math.sqrt(xpPoints));
return level;
}
3.1 - Update the engine
You will have to compare the old xpPoints and the new xpPoints from the user. If get the points needed for level up the bot have to send a message saying the new level for the user
4 - Command for profile
So the user can see the xp points and level. You will have to get the data of xpPoints when userID and guildID are the same from the message user ID and guild ID
5 - Command for rank
You will have to sort the data of xpPoints from the database where the guildID is equal to the message guild ID. And then show the first 5 or 10 users.
6 - Improve whatever you want
This is just a quick example, you can improve in a lot of ways
const xp = 100; // current amount of XP that member has
const goal = 200; // amount of XP that member needs to reach next level
const level = 1; // current level that member has
console.log(`You need ${goal - xp} more XP to reach lvl.${level + 1}`);
// the line above will print the following: "You need 100 more XP to reach lvl.2"