Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
MongoDB row as variable Javascript Discord

I building a game thingy where you can trade and stuff. I'm currently making the admin command for it, so that you can give members amounts of materials. Here is the code:

      try {
        const targetData = await profileModel.findOne({ userID: target.id });
        if (!targetData) {
          return message.channel.send(config.basemessages.messagesaccountmissing);
        }
        await profileModel.findOneAndUpdate(
          {
            userID: target.id,
          },
          {
            $inc: {
              bank: amount,
            },
          }
        );

        message.channel.send(`The targeted member has been given \`${amount}\` amount of \`${material}\`.`)
      } catch (err) {
        console.log(err);
        message.channel.send(`Error executing command. EC: \`${config.errorcodes.err2}\`.`) // Error Systeem
      }

Since I have 200+ different items, it would be inefficient if I copy this block 200+ times just to give someone a item. The problem is that bank should be the exact name of a row in a MongoDB document. I just discovered that you can't make that a variable (or so I think). I want to replace that with for example material, where material is args[1] (the perimeter). Example usage:

$give @member iron 40
  • Member = the target Discord member (args[0])
  • Iron = the material that I want to increase (args[1])
  • 40 = amount to increase (args[2])

I hope it's clear what I mean. Is there a work around this? (Only the bank perimeter doesn't work, the amount does work with a variable).

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda