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

267
Vistas
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 Respuestas
Responde la pregunta

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