Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!