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

265
Visualizações
Discord js How I can search for userID in json file using for...in

The problem I have is when I use this loop, I only get the guild id, but I need to get the user id. My Code:

for(let userID in money){
    res.push({"guildid": message.guild.id, "id": userID, "money": money[message.guild.id][userID].money })
    res.sort((a, b) => Object.values(b)[1] - Object.values(a)[1])
    console.log(userID);
}

My JSON file:

{
"2543634674355 <======GuildID":
    {"309781817504956426 <======userID":
     {       "name":"user1#7777",
             "money":15000},
     "868630066064654397 <======userID":
{            "name":"user2#7777",
             "money":0}},
"402469770760421406 <======GuildID":
{    "309781817504956426 <======userID":
{            "name":"user1#7777",
             "money":0
}
}
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

for (let userID in money[message.guild.id]) {
  // Your code
}

Very basic javascript, very basic logic. Just go through the logic: you want to loop through all of the user ID data in the current guild, contained in the JSON file (assuming the money variable contains the JSON data). So get the current guild data from the JSON data (money[message.guild.id]), and then loop through the user IDs in it with the for/in loop.

Nothing to it. You may want to go through some Javascript tutorials and get more acquainted with Javascript while/before diving into discord bot programming, so you can better understand how to code this type of logic.

about 4 years ago · Juan Pablo Isaza Relatório
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