G
G
Genkail2019-05-10 09:34:40
JavaScript
Genkail, 2019-05-10 09:34:40

How to make a level system in discord?

Can someone send the code for the level system in discord? (for example, I got a level (levels are issued for a certain number of messages) - a role was issued, received a 2nd level - a role for the first level climbed and issued for 2)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-08-10
@Alexandre888

https://www.youtube.com/watch?v=E5TVwyiCuYA

A
AlmondPark33609, 2021-09-17
@AlmondPark33609

Hello! I know that you already know the answer to the question. But I will answer for those who will watch it.

let db = require('quick.db') // для примера использую простой в использовании пакет БД "quick.db"
let discord = require('discord.js')
let client = new discord.Client()

client.on('message', async (message) => {

let uid = message.author.id
let sid = message.guild.id
let xp = db.get(`xp_${sid}_${uid}`)
let lvl = db.get(`lvl_${sid}_${uid}`)


if (xp == null){
   db.set(`xp_${sid}_${uid}`, 0)
   xp = 0
}
if (lvl == null){
   db.set(`lvl_${sid}_${uid}`, 1)
   lvl = 1
}
db.add(`xp_${sid}_${uid}`, 1)
if (xp >= (lvl * 10)){ // прибавляем уровень если очков опыта больше/равно чем уровней в 10 раз
   db.add(`lvl_${sid}_${uid}`, 1) // добавляем 1 уровень
   db.set(`xp_${sid}_${uid}`, 0) // сбрасываем очки опыта
   message.channel.send(`${message.author}, ты поднял(-а) уровень!`)
}
})

That's a simple level system! And how to issue roles is on the Internet
Of course, you can use any database or even a JSON file
Version discord.js 12.5.3

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question