1 回答
TA贡献1998条经验 获得超6个赞
在你的问题中,级别可以很容易地是一个数组(在 JSON 文件中):
levels : [0, 100, 300, 1000, 5000]
然后你可以根据它匹配的最低条目检查exp,这将是你的级别
for(let i = 0; i < levels.length; i++) {
if (memberExp[message.author.id].exp > levels[i]) {
memberExp[message.author.id].level = i
}
}
更新
我添加了等级检查,这样你就可以看到你获得了多少等级
// 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!`)
}
添加回答
举报