[OLD] Discord.js Leveling System

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.

You should try with Database.

Check this out: Enmap based Level System

1 Like

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

2 Likes

I tried doing that but it lead to errors, etc in the code and didn’t work.

@onyx6227
Can you give your error please

It says client is not defined and some errors in my bot.js

Define client as

const client = new discord.Client()

@SudhanPlayz,

Typo!

const client = new Discord.Client();

Typo
I USUALLY CONSIDER DISCORD as discord lol

@onyx6227, you might have defined it as

const bot = new Discord.Client();

This declaration is also common!

@onyx6227

I have a Discord.js Leveling System with a JSON Database

1 Like

Ok ill try it since the other one isnt working.

Would I be able to turn leveling on and off because my bot got rejected because he couldnt turn leveling off.

maybe you should do like

{
"leveling": true
}

I also have same problem can i use that?

can you do

const bot = new Discord.Client();
or does it not work

The variable shouldn’t matter, that should work.

Could u tell me how i can determine how much xp is needed to react a sertain level?

For example, when i am level 5 how much xp do i need to reach lvl 6.

i use the following formula:
const nxtLvl = Math.floor(0.13 * Math.sqrt(data.xp));

I hope you can help :slight_smile:

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"

Simple as this.