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

141
Visualizações
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 Respostas
Responde à pergunta

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