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

301
Vistas
What event should be used for checking when a user's custom status updates?

I'm trying to make a vanity bot for Discord, but I'm not sure if I'm using the correct event. Here is my code:

client.on("presenceUpdate", newPresence => {
    let vanityRole = newPresence.guild.roles.cache.find(role => role.id === "940679835456536596");
  const activity = newPresence.member.user.presence.activities[0].state
  if (activity === null) return;
  if (activity.includes("gg/pm")) {
    let memberTarget = newPresence.guild.members.cache.get(newPresence.member.id);
    memberTarget.roles.add(vanityRole);
    const vanity = new Discord.MessageEmbed()
      .setColor(color)
      .setDescription(`<@${memberTarget.id}>, thanks for putting us in your status <3`);
      message.channel.send(vanity)
  }
  else return;
});

Here is the error I'm receiving: On this line: const activity = newPresence.member.user.presence.activities[0].state Error: [TypeError: Cannot read property 'state' of undefined] repl process died unexpectedly: exit status 1

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

One of your items at newPresence.member.user.presence.activities is equal to an empty array or undefined, therefore newPresence.member.user.presence.activities[0] === undefined.

You can try: const activity = newPresence.member.user.presence.activities[0]?.state

The optional chaining operator (?.) enables you to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid.

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