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?

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

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
}