我想为我的机器人创建一个卖出命令,并且已经使用教程进行了余额,库存和购买命令。我创造了一些赚钱的方式,例如日常命令和工作命令。这是我的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)
}
}
}
}
我将如何使用此命令创建一个卖出命令?
答案 0 :(得分:0)
我看到您的代码,并且在if(args[0] === "sword")
中发现错误。
所以,我将解释什么是错误。在.content
之后没有包含属性.includes()
或args[0]
,因此漫游器无法检查参数是否包含“ sword”。
使用以下一种方法修复它:
if(args[0].content === "sword"){
//code here
}
OR
if(args[0].includes('sword'){
//code here
}
您可以查看此链接以获取更多信息: