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

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

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