I was creating a coinflip for my casino system, but it's not working than what I expected. Did I missed something?
But in my other commands, it's working fine just this one not working
if(!args[0]) { const embed = new MessageEmbed() .setTitle("Casino Coinflip") .setDescription("You need to choose
head | tail` then <amount>")
.setColor('RANDOM')
.setTimestamp()
message.channel.send({embeds: [embed]})
} else if(args[0] === 'heads' || args[0] === 'heads' || args[0] === "h") {
const exist = await economy.findOne({
guildID: message.guild.id
})
if(!exist) return message.reply("You don't have records yet to gamble")
const amount = parseFloat(args[1])
if(amount > exist.wallet) return message.reply(`You dont have enough balance, your current balance is $${exist.wallet.toLocaleString()}`)
let RN = Math.floor(Math.random() * 100) 1
if(RN > 50) {
economy.findOneAndUpdate({
guildID: message.guild.id
}, {$inc: {wallet: amount}}, async(err, data) => {
data.wallet = amount
data.save()
message.channel.send(`You bet for ${args[0]} and won $${amount.toLocaleString()}!`)
})
} else {
economy.findOneAndUpdate({
guildID: message.guild.id
}, {$inc: {wallet: amount}}, async(err, data) => {
data.wallet -= amount
data.save()
message.channel.send(`You bet for ${args[0]} and lost ${amount.toLocaleString()}!`)
})
}
} else if(args[0] === "tails" || args[0] === "tail" || args[0] === "t") {
const exist = await economy.findOne({
guildID: message.guild.id
})
if(!exist) return message.reply("You don't have records yet to gamble")
const amount = parseFloat(args[1])
if(amount > exist.wallet) return message.reply(`You dont have enough balance, your current balance is $${exist.wallet.toLocaleString()}`)
let RN = Math.floor(Math.random() * 100) 1
if(RN > 50) {
economy.findOneAndUpdate({
guildID: message.guild.id
}, {$inc: {wallet: amount}}, async(err, data) => {
data.wallet = amount
data.save()
message.channel.send(`You bet for ${args[0]} and won $${amount.toLocaleString()}!`)
})
} else {
economy.findOneAndUpdate({
guildID: message.guild.id
}, {$inc: {wallet: amount}}, async(err, data) => {
data.wallet -= amount
data.save()
message.channel.send(`You bet for ${args[0]} and lost ${amount.toLocaleString()}!`)
})
}
}`
CodePudding user response:
You only forgot one code line which is the author you need to find into the data base,
userID: message.author.id //this will be the author who using the command
or whatever you put on your schema, might be userID
, userId
, memberID
, memberId
If you didn't put the message.author.id
on your findOne
it will only picked the first data on your database, that's why you keep getting 0 balance even you have balance on your database.