如何解决 quick.db 不产生负输出的问题
how to fix that quick.db doesn't make a negative output
我正在用我的 discord 机器人做一个经济系统。一切顺利,但是当我使用一些减法命令或取款命令时,或者你的余额将被减去
它变成了负数,就像我减去我的余额到 50 但我的余额只有 25 现在我的余额现在是 -25 如何解决它??
我的余额文件:
module.exports ={
name:'bal',
description: "bal for user",
execute(message, args, Discord, db){
const target = message.mentions.users.first() || message.author
const targetid = target.id
if(db.get(`user_${targetid}.bal`) === null){
message.channel.send('you need to create an account')
}else{
let bal = db.get(`user_${targetid}.bal`)
let bank = db.get(`user_${targetid}.bank`)
let embed = new Discord.MessageEmbed()
.setTitle(`${target.username} BALANCE`)
.setColor('GREEN')
.setDescription(`coins: ${bal} Cheese Coins \nbank: ${bank} Cheese Coins`)
message.channel.send(embed)
}
}
}
我的减法文件:
module.exports ={
name:'sub',
description: "sub",
execute(message, args, Discord, db){
const hey = message.mentions.users.first()
const number = args[1]
if(!hey){
message.channel.send('Mention someone or ill take yours')
}else if(!number){
message.channel.send('Put a number, take it or leave it')
}else{
let embed = new Discord.MessageEmbed()
.setTitle('Poor speedrun Any%')
.setColor('YELLOW')
.setDescription(`Total of ${number} money has revoked been from ${hey}, **SAD ${hey} NOISES**`)
db.subtract(`user_${hey.id}.bal`, number)
message.channel.send(embed)
}
}
}
验证用户余额是否小于您尝试减去的金额。
const userbalance = db.get(`user_${hey.id}.bal`);
if(userbalance < number) return;
db.subtract(`user_${hey.id}.bal`, number)
我正在用我的 discord 机器人做一个经济系统。一切顺利,但是当我使用一些减法命令或取款命令时,或者你的余额将被减去 它变成了负数,就像我减去我的余额到 50 但我的余额只有 25 现在我的余额现在是 -25 如何解决它??
我的余额文件:
module.exports ={
name:'bal',
description: "bal for user",
execute(message, args, Discord, db){
const target = message.mentions.users.first() || message.author
const targetid = target.id
if(db.get(`user_${targetid}.bal`) === null){
message.channel.send('you need to create an account')
}else{
let bal = db.get(`user_${targetid}.bal`)
let bank = db.get(`user_${targetid}.bank`)
let embed = new Discord.MessageEmbed()
.setTitle(`${target.username} BALANCE`)
.setColor('GREEN')
.setDescription(`coins: ${bal} Cheese Coins \nbank: ${bank} Cheese Coins`)
message.channel.send(embed)
}
}
}
我的减法文件:
module.exports ={
name:'sub',
description: "sub",
execute(message, args, Discord, db){
const hey = message.mentions.users.first()
const number = args[1]
if(!hey){
message.channel.send('Mention someone or ill take yours')
}else if(!number){
message.channel.send('Put a number, take it or leave it')
}else{
let embed = new Discord.MessageEmbed()
.setTitle('Poor speedrun Any%')
.setColor('YELLOW')
.setDescription(`Total of ${number} money has revoked been from ${hey}, **SAD ${hey} NOISES**`)
db.subtract(`user_${hey.id}.bal`, number)
message.channel.send(embed)
}
}
}
验证用户余额是否小于您尝试减去的金额。
const userbalance = db.get(`user_${hey.id}.bal`);
if(userbalance < number) return;
db.subtract(`user_${hey.id}.bal`, number)