为什么 data.wallet 一直发送 0 值?

Why data.wallet keeps sending 0 value?

我正在为我的赌场系统创建一个投币游戏,但它的效果不如我预期。我错过了什么吗?
但是在我的其他命令中,它工作正常,只是这个命令不起作用,因为它类似于我在命令中的所有工作。但是这个一直给我 0 余额应该是 1e9 它 parseFloat

        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()}!`)
                })
            }
        }`

你只忘记了一个代码行,你需要到数据库中找到作者,

userID: message.author.id //this will be the author who using the command

或您放在模式中的任何内容,可能是 userIDuserIdmemberIDmemberId

如果你没有把 message.author.id 放在你的 findOne 上,它只会选择你数据库中的第一个数据,这就是为什么即使你的数据库有余额,你的余额也会一直为 0。