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

在discord.js中,我想使用quick.db为我的机器人的货币系统创建一个sell命令,discord.js,quick.db,Discord.js,Quick.db,我想为我的机器人创建一个sell命令,我已经使用教程创建了一个balance、inventory和buy命令。我创造了一些赚钱的方法,比如日常命令和工作命令。这是我的buy命令代码 const Discord = require("discord.js") const db = require("quick.db") module.exports = { name: "buy", description: "

我想为我的机器人创建一个sell命令,我已经使用教程创建了一个balance、inventory和buy命令。我创造了一些赚钱的方法,比如日常命令和工作命令。这是我的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)
            }
        }
    }
}
const Discord=require(“Discord.js”)
const db=require(“quick.db”)
module.exports={
名称:“购买”,
描述:“购买物品”,
执行:异步(客户端、消息、参数)=>{
让author=db.fetch(`money\u${message.author.id}`)
如果(!args[0]){
message.channel.send(“您想买什么?”)
}
如果(参数[0]=“剑”){
如果(作者<200){
message.reply(“您没有足够的ihscoins购买此商品!”)
}否则{
让items=db.fetch(message.author.id,{items:[]})
db.push(message.author.id,“剑”)
message.channel.send(“您购买了1把剑!”)
db.subtract(`money${message.author.id}`,200)
}
}
}
}

如何使用此命令创建sell命令?

我看到了您的代码,并在
if(args[0]==“swarm”)
中发现了一个错误

因此,我将解释错误是什么。在
args[0]
之后未包含属性
.content
.includes()
,因此bot无法检查参数是否包含“剑”

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

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

有关详细信息,请查看此链接:

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