Reputation: 79
Im making an addmoney cmd for my discord bot but when the money, it gets added weirdly. Eg. normally it would be 200 if i add 100 and there was already 100 but im my occasion its 100100. Anyways code:
const { QuickDB } = require('quick.db');
const db = new QuickDB();
const discord = require("discord.js")
module.exports.run = async (bot, message, args) => {
if (!message.member.permissions.has("ADMINISTRATOR")) return message.reply("You do not have the permissions to use this command😔.")
if (!args[0]) return message.reply("Please specify a user❗")
let user = message.channel.members.first() || message.guild.members.cache.get(args[0]) || messsage.guild.members.cache.find(r => r.user.username.toLowerCase() === args[0].toLocaleLowerCase()) || message.guild.member.cache.find(r => r.displayName.toLowerCase() === args[0].toLocaleLowerCase())
if (!user) return message.reply("Enter a valid user⛔.")
if (!args[1]) return message.reply("Please specify the amount of money💰.")
var embed = new discord.MessageEmbed()
.setColor("#C06C84")
.setAuthor(message.author.tag, message.author.displayAvatarURL({dynamic: true}))
.setDescription(`Cannot give that much money⛔.
Please specify a number under 10000💸.`)
.setTimestamp()
if (isNaN(args[1]) ) return message.reply("Your amount is not a number❗.")
if (args[0] > 10000) return message.reply({embeds: [embed]})
await db.add(`money_${user.id}`, args[1])
let bal = await db.get(`money_${user.id}`)
let moneyEmbed = new discord.MessageEmbed()
.setColor("#C06C84")
.setDescription(`Gave $${args[1]} \n\nNew Balance: ${bal}`)
message.reply({embeds: [moneyEmbed]})
}
module.exports.help = {
name: "addmoney",
category: "economy",
description: 'Adds money!',
}
Upvotes: 0
Views: 195
Reputation: 2337
One way you could get this kind of behaviour is if args[1]
was a string. In that case, instead of adding the value, it would just concatenate it with the current value of money_${user.id}
. So, to fix it all you have to do is, instead of passing it directly, use parseInt()
and then pass it. Then, your fixed part might look like this =>
await db.add(`money_${user.id}`, parseInt(args[1]))
Upvotes: 1