0

This might be a pretty simple solution but I am really lost with it. In my discord economy bot, I have fully developed an inventory system - where user can buy items from the shop, store them in their inventory and use them at will. The simple problem I am facing is when the user has two items of the same kind (for example - like car) , the items will show up in their inventory twice like- car car

instead of it, I want the embed to be shown as- car x2

I am thinking about using loops but I am not sure if I am doing the right way. I can continue if I get a general idea of how to implement it! Please help me!!

The following is my simplified items command!

const db = require ('quick.db')
const Discord  = require ('discord.js')


module.exports = {

commands : ["items","i"],
alias : ["i"],


callback : async (message,arguments,text) => {

    const target = message.mentions.members.first () || message.author

 let items = db.fetch (`itm_${target.id}`)
if (items === null || !items[0]) (items = "No items here")
const embed = new Discord.MessageEmbed ()
.setTitle (`${target}'s items`)
.addFields (

    {name : "items", value:items}
)
.setColor ("#ECB802")


message.channel.send (embed)
}



}

Ren
  • 27
  • 5
  • Could you show what `items` looks like? – Lioness100 Apr 25 '21 at 16:50
  • it is basically an array used to store datas- for example like `db.set (`itm_${message.author.id}`, ["item1", "item2"]` – Ren Apr 25 '21 at 16:52
  • Does this answer your question? [How to count duplicate value in an array in javascript](https://stackoverflow.com/questions/19395257/how-to-count-duplicate-value-in-an-array-in-javascript) – Lioness100 Apr 25 '21 at 17:06
  • Yep ! I got an general idea to how to do that now!! Thank you so much for replying! – Ren Apr 25 '21 at 17:36

0 Answers0