Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

257
Vistas
a discord.js inventory system that shows full list

I've been trying to figure out how to make an inventory system that shows the whole list of that categories items + a users quantity of that item, for example:

if someone does >inv fruits, it would show:

  • apple - 0
  • banana - 1
  • orange - 3

if they did >inv candy, it would show a diff list of items:

  • chocolate - 2
  • lollipop - 0
  • skittles - 0

I store the user_id, category, item and quantity in my database table and I've got the list of items in a category stored in a JSON file.

Right now I've only figured out how to pull the item and quantity that a user has from the database but how would I show the list of items and match the name of item to quantity like the examples above?

CODE SO FAR:

const ValidGroup = args[0];

getInventory(user_id = `${message.author.id}`, group_name = `${ValidGroup}`).then(([rows]) => {

            const InvEmbed = new MessageEmbed()
            .setAuthor(`${message.author.username} | Inventory`)
            .setTimestamp();

            let cardString = " ";
            
            Object.keys(rows).forEach(function (key) {

                //GET DATA
                const row = rows[key];
                let cardCode = row.card_name;
                let cardQuan = row.quanity;

                //CARD ARRAY FORMAT
                let cardArray = `${Code} | ${CardFullName} - ${cardQuan}`
                let invArray = cardArray.split("\n")
                cardString += `\n${invArray}`
            });


            InvEmbed.setDescription(cardString);

            message.channel.send({ embeds: [InvEmbed] });

        });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The first thing I realised while reading your code was the part where you did this:

cardArray.split("\n")

First of all, cardArray is not an array. If it is an array, you should specify what each thing is in params, as people cannot understand what a certain thing is unless if you mention. You can learn how to do this at: https://jsdoc.app/tags-param.html.

cardArray is a string!

const ValidGroup = args[0];

getInventory(user_id = `${message.author.id}`, group_name = `${ValidGroup}`).then(([rows]) => {
  const InvEmbed = new MessageEmbed()
  .setAuthor(`${message.author.username} | Inventory`)
  .setTimestamp();

  let cardString = " ";

  Object.keys(rows).forEach(function (key) {
    //GET DATA
    const row = rows[key];
    let cardCode = row.card_name;
    let cardQuan = row.quanity;

    //CARD ARRAY FORMAT
    let card = `${Code} | ${CardFullName} - ${cardQuan}`
    cardString += `${card}\n`
  });

  InvEmbed.setDescription(cardString);

  message.channel.send({ embeds: [InvEmbed] });
});

I've changed the code by removing invArray and replacing cardArray with 'card'. I've also replaced the \n at the front and moved it to the back, therefore there wouldn't be an extra break at the start of your description.

You can also try adding error catching or checking if the user has anything in their inventory, otherwise it may cause certain errors such as a the MessageEmbed having an empty description.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda