in ,

Create Level System For Discord Bot Easily

Hi guys, Welcome back to the brand-new post of mine. Today I will show you how you can Create Level System For Discord Bot Easily. Lets get directly to the point.

How To Create Level System For Discord Bot Easily

Create Level System For Discord Bot Easily

First of all we will create class in different .js file, Given below class is created by me and my friend

const db = require("quick.db")

class Util {
  static getLevel(xp, extra = false) {
  let level = 0;
    while(xp >= Util.getLevelxp(level)) {
      xp -= Util.getLevelxp(level);
    if(extra) return [level, xp];
    else return level;

  static getLevelxp(level) {
    return 5 * Math.pow(level, 2) + 50 * level + 100;
  static getInfo(exp) {
    let [level, remxp] = Util.getLevel(exp, true);
    let levelxp = Util.getLevelxp(level);
    return { level, remxp, levelxp}
  static addexp(message) {
    let toadd = Math.floor(Math.random() * 3 + 3);
    let oldxp = db.get(`xp_${}_${}`)
    let oldlvl = Util.getLevel(oldxp)
    let newxp = oldxp = toadd;
    let newlvl = Util.getLevel(newxp);
    if(newlvl > oldlvl)`${}, You just reached level ${newlvl}`)
    db.add(`xp_${}_${}`, toadd)

module.exports = Util;

We will be using it for our level system, I suggest you to look up codes properly and try to understand.

Now go to main file, in my case my main file is server.js and add exp to author data by using addexp(message) and you need to define addexp also

const { addexp } = require("./handlers/xp.js")

client.on("message", async message => {
if( return;
  if(!message.guild) return;
return addexp(message)

Now lets go and create level command for bot, first we will be defining user

 const user = message.mentions.users.first() ||;

After defining user we will make sure that author does not mention its own bot

   if( === { //IF BOT
      return"😉 | I am on level 100")

Now we will make sure that author does not mention any bot because we can’t let bot have xp

 if( {
      return"Bot do not have levels")

Well it’s time to define XP and we are using quick.db for storing XP for every user per server and before that don’t forget to define getInfo and quick.db

 let xp = db.get(`xp_${}_${}`) || 0;
    const {level, remxp, levelxp} = getInfo(xp);

We also make sure if user have 0 XP bot will send alert message.

if(xp === 0) return`**${user.tag}** is out of the xp`)

Now we will send embed with all level details

let embed = new discord.MessageEmbed()
    .setAuthor(user.username, message.guild.iconURL())
    .setDescription(`**LEVEL** - ${level}
**XP** - ${remxp}/${levelxp}`)   

You are done here and ready to use the bot

Re>Result Code

Here is the result code of whole repo – HERE

Also Read: Creating Pokedex Command for Discord Bot Using API and discord.js v12

Related Posts

Written by Senpai

"This may be a virtual world,but I feel more alive here then in the real world"

Leave a Reply