I am doing an economic system at my discord bot. It went well but when I use some subtract command or withdraw command or your balance will be subtract it got to negative number like I minus my balance to 50 but my balance is only 25 now my balance is now -25 how to fix it??
My balance file:
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)
}
}
}
My substract file:
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)
}
}
}
Verify if the userbalance is less than the amount you trying to substract.