I'm adding a deposit command but when I try to add the amount into the bankBalance, it doesn't add them correctly into integers, this may sound confusing, I'll give you an example.
Example:
Command: ~deposit 100,
User balance: Wallet: 120, Bank: 0,
Output user balance: Wallet: 20, Bank: 0100
I wish this explains it, anyways here is my code:
const { MessageEmbed } = require('discord.js');
const Database = require('@replit/database');
const db = new Database();
module.exports = {
name: 'deposit',
aliases: ['dep'],
category: 'Economy',
description: 'Deposits all or a amount of balance into the bank.',
usage: 'deposit',
userperms: [],
botperms: [],
run: async (client, message, args, prefix) => {
if (message.author.bot) return;
let walletBalance = await db.get(`wallet_${message.author.id}`)
let bankBalance = await db.get(`bank_${message.author.id}`)
if (walletBalance === null) walletBalance = 0
if (bankBalance === null) bankBalance = 0
console.log(walletBalance, bankBalance)
let amount = args[0]
if (!amount) amount = walletBalance
if (walletBalance == 0) return message.reply('You don\'t have any money!')
if (amount) {
if (isNaN(amount)) {
if (amount.toLowerCase().includes('all')) amount = walletBalance;
}
if (isNaN(amount)) return message.reply('The amount must be a number!')
if (amount > walletBalance) return message.reply('You don\'t have enough balance in your wallet to do this!')
if (amount) {
await db.set(`wallet_${message.author.id}`, walletBalance - amount).then(
await db.set(`bank_${message.author.id}`, bankBalance + amount).then(
message.reply(`Successfully deposited ${amount.toLocaleString()} into your bank!`)
)
)
}
}
}
}
Note: I'm using replit