在discord.js中,我想使用quick.db为我的机器人创建一个货币系统的卖出命令

问题描述

我想为我的机器人创建一个卖出命令,并且已经使用教程进行了余额,库存和购买命令。我创造了一些赚钱的方式,例如日常命令和工作命令。这是我的buy命令代码

const discord = require("discord.js")
const db = require("quick.db")

module.exports = {
    name: "buy",description: "buy an item",execute: async(client,message,args) => {
        let author = db.fetch(`money_${message.author.id}`)

        if (!args[0]) {
            message.channel.send("What are you trying to buy?")
        }

        if (args[0] === "sword") {
            if (author < 200) {
                message.reply("You don't have enough ihscoins to buy this item!")
            } else {
                let items = db.fetch(message.author.id,{ items: [] })
                db.push(message.author.id,"Sword")
                message.channel.send("You have bought 1x Sword!")
                db.subtract(`money_${message.author.id}`,200)
            }
        }
    }
}

我将如何使用此命令创建一个卖出命令?

解决方法

我看到您的代码,并且在if(args[0] === "sword")中发现错误。

所以,我将解释什么是错误。在.content之后没有包含属性.includes()args[0],因此漫游器无法检查参数是否包含“ sword”。

使用以下一种方法修复它:

if(args[0].content === "sword"){
//code here
}

OR

if(args[0].includes('sword'){
//code here
}

您可以查看此链接以获取更多信息:

Message#content | discord.js