1 回答

TA貢獻(xiàn)1998條經(jīng)驗(yàn) 獲得超6個(gè)贊
在你的問題中,級(jí)別可以很容易地是一個(gè)數(shù)組(在 JSON 文件中):
levels : [0, 100, 300, 1000, 5000]
然后你可以根據(jù)它匹配的最低條目檢查exp,這將是你的級(jí)別
for(let i = 0; i < levels.length; i++) {
if (memberExp[message.author.id].exp > levels[i]) {
memberExp[message.author.id].level = i
}
}
更新
我添加了等級(jí)檢查,這樣你就可以看到你獲得了多少等級(jí)
// remember the old level
let previousLevel = memberExp[message.author.id].level
// level up according to xp
for(let i = 0; i < levels.length; i++) {
if (memberExp[message.author.id].exp > levels[i]) {
memberExp[message.author.id].level = i
}
}
// check how many levels we gained
let amountGained = memberExp[message.author.id].level - previousLevel
// if we gained more than 0 we can display a message
if(amountGained > 0) {
console.log(`Congrats! You gained ${amountGained} levels!`)
}
添加回答
舉報(bào)