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

237
Visualizações
How to fetch data which is not cached?

When I try to interact with data an error is thrown.

const user = client.users.cache.get(user.id);
user.send(message);

TypeError: Cannot read property 'send' of undefined

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Explanation of cache utility

Cache is a Collection, an extend of Map but with array methods and more. It's mainly used by managers and used to prevents useless API calls, when data is fetched it will be cached too and you will be able to retrieve it how many time you want without sending API request. So when data is not cached it means that the data was not fetched yet and you'll need to.

A request is a call to the Discord API which is done by the Discord.js module, to wait the response of the Discord server, the Promise need to be awaited with await keyword or <Promise>.then method.

Fetch example

You can fetch data and assign the response in a variable, when you want to access it another time you will be able to retrieve data in the cache.

/* Data wasn't fetched so not cached yet */
console.log(client.users.cache.get(user.id)); // undefined

/* Request data from Discord */
const fetchedData = await client.users.fetch(user.id);
console.log(fetchedData); // User {}

/* Data has been fetched so you can retrieve data from cache */
console.log(client.users.cache.get(user.id)); // User {}

After these explanations, it's normal that this error appears since it's not possible to apply a method on something undefined.

TypeError: Cannot read property '' of undefined

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