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

140
Views
Discord bot not fetching user data even when user id is there

I am using discord v13.6.0 . I have a 2d array in which data looks like this

[
 [ 'userID', 0 ],
 [ 'userID2', 0 ],
]

Here is my code .

  let index;
        for(index=0;index<items.length;index++){
          if(items[index][0]==msg){
            break;
          }
  }
        console.log("In is ",index);
        if(index==0){
          rank = 1;
          let j=index+2;
          let k = index + 1;
          let currentUserId = items[index][0];
          let nextUserId = items[k][0];
          console.log(nextUserId);
          let nextUserId2 = items[j][0];


          let currentUserTag = client.users.cache.get(currentUserId);
          let currentName = currentUserTag.username;
          let nextUserTag = client.users.cache.get(nextUserId);
          let nextUserName = nextUserTag.username;


          console.log(currentName);
          console.log(nextUserName);

Now I am getting a error here. My code shows me curretName but it is giving me a error for the nextUserName. My error is this

TypeError: Cannot read properties of undefined (reading 'username') at E:\DiscordBotTesting\LeaderBoard\LeaderboardRankingsystem.js:217:42

I am fetching array data from firebase and making it a 2d array. That value in 2d array is being used to fetch user data in discord server where I am trying to get username.

Please help why I am getting the currentname but not for nextUsername. Funny thing is same code is working for discord v12 but fails for discord v13.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Maybe not using the cache, but not sure:

let index;
        for(index=0;index<items.length;index++){
          if(items[index][0]==msg){
            break;
          }
  }
        console.log("In is ",index);
        if(index==0){
          rank = 1;
          let j=index+2;
          let k = index + 1;
          let currentUserId = items[index][0];
          let nextUserId = items[k][0];
          console.log(nextUserId);
          let nextUserId2 = items[j][0];


          let currentUserTag = client.users.cache.get(currentUserId);
          let currentName = currentUserTag.username;
          let nextUserTag = async id => client.users.fetch(id)
          let nextUserName = nextUserTag.username;


          console.log(currentName);
          console.log(nextUserName);
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!