-2

我想为我的机器人创建一个销售命令,并且我已经使用教程进行了平衡、库存和购买命令。我创造了一些赚钱的方法,比如日常命令和工作命令。这是我的购买命令代码。

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)
            }
        }
    }
}

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

4

1 回答 1

0

我看到你的代码,我发现if(args[0] === "sword").

所以,我将解释什么是错误。您没有包含属性.content.includes()after args[0],因此机器人无法检查参数是否包含“剑”。

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

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

或者

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

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

留言#内容 | 不和谐.js

于 2020-09-10T12:51:37.737 回答