简体   繁体   English

Quick.db .add 功能无法正常工作

[英]Quick.db .add function not working correctly

Im making an addmoney cmd for my discord bot but when the money, it gets added weirdly.我为我的不和谐机器人制作了一个 addmoney cmd,但是当有钱时,它会被奇怪地添加。 Eg.例如。 normally it would be 200 if i add 100 and there was already 100 but im my occasion its 100100. Anyways code:通常如果我加 100 并且已经有 100 则为 200 但我的场合是 100100。无论如何代码:

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!',
}

One way you could get this kind of behaviour is if args[1] was a string.获得这种行为的一种方法是如果args[1]是一个字符串。 In that case, instead of adding the value, it would just concatenate it with the current value of money_${user.id} .在这种情况下,它不会添加该值,而是将其与money_${user.id}的当前值连接起来。 So, to fix it all you have to do is, instead of passing it directly, use parseInt() and then pass it.因此,要修复它,您所要做的就是使用parseInt()然后传递它,而不是直接传递它。 Then, your fixed part might look like this =>然后,您的固定部分可能看起来像这样 =>

await db.add(`money_${user.id}`, parseInt(args[1]))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM