-2

I want to create a sell command for my bot and I have already made a balance, inventory and buy command using tutorials. I have created ways to get money like a daily command and also a work command. Here is my code for the buy command.

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

How would I create a sell command using this?

IhsFace
  • 13
  • 4

1 Answers1

0

I see your code and I found an error in if(args[0] === "sword").

So, I will explain what's the error. You did not includes the property .content or .includes() after args[0], so the bot can't check if the argument includes "sword".

Fix it using one of this methods below:

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

OR

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

You can check this link for more information:

Message#content | discord.js

YaeDev
  • 59
  • 4