Answer the question
In order to leave comments, you need to log in
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
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}, ты поднял(-а) уровень!`)
}
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question