簡體   English   中英

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

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

我為我的不和諧機器人制作了一個 addmoney cmd,但是當有錢時,它會被奇怪地添加。 例如。 通常如果我加 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!',
}

獲得這種行為的一種方法是如果args[1]是一個字符串。 在這種情況下,它不會添加該值,而是將其與money_${user.id}的當前值連接起來。 因此,要修復它,您所要做的就是使用parseInt()然后傳遞它,而不是直接傳遞它。 然后,您的固定部分可能看起來像這樣 =>

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM