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

210
Visualizações
Finding a certain users status in discord.js

Okay so I am trying to make a discord bot that detects when a certain user is online in my server. But every time I try to get the users presence status it always says "const usersStatus = user.presence.status; TypeError: Cannot read properties of undefined (reading 'status')". How do I get the presence status of a specific user? Here's my code so far

const { Client, Intents } = require('discord.js');
const { token} = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_PRESENCES] });

const user = client.users.fetch('Users ID');
const usersStatus = user.presence.status;

client.once('ready', () => {
    console.log("should be online");
    console.log(usersStatus);
})

//place at end of file
client.login(token);
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

In Discord, offline members don't have any presence, so the presence is null, hence you get the error.

So if presence is null, either the User defined isn't a user or they are offline.

Secondly, you will need to resolve the promise by adding await

Usually, I would do this to get to know their status.

let user = await client.users.fetch("ID")
console.log(`${user.tag}'s presence status: ${user.presence?.status ?? "offline"}`)

This will log for example: Ashish#0540's presence status: dnd if the person is on do not disturb, or Ashish#0540's presence status: offline

about 4 years ago · Juan Pablo Isaza Relatório

0

client.users.fetch returns a Promise. You will need to await it and get the presence from there

(async () => { //await needs async
const user = await client.users.fetch('Users ID');
const usersStatus = user.presence.status
})()

Additionally, you won't get any users if the client is not ready. You should make sure this is in your ready event so the client fetches the user properly.

In discord.js v13 Users don't have presences. This is only on GuildMembers now. I believe this is for security reasons - like bots can only DM members they are in a guild with. You can get any guild that this user is in, then get the member from there where you will then get their status

const member = await guild.members.fetch('Users ID'); //remember you still need async
const membersStatus = member.presence.status
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