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

204
Vistas
Discord Rich Prescence timestamp & name

I'm making a discord bot in JS that when the command is called says "User has been playing GameName for Hours". My code currently works if the mentioned user is playing a game that lacks rich prescence support, but if a game like League of legends is called alongside the user, I get the error TypeError: Cannot read property 'presence' of undefined. While I know what this means, it is the way I reference the mentioned user's presence found in the code below.

const { Client, Intents } = require('discord.js');

module.exports = {
    name: 'test',
    aliases: [],
    category: 'test',
    utilisation: '',

    execute(client, message, presence, guild) {
        let msgMention = message.mentions.members.first()

        let mp = msgMention.presence.activities[0]

        if (msgMention.presence.activities[0].name == "Spotify"){
            var imgvar = mp.assets.largeImage
            var imgvar = imgvar.replace('spotify:','')
            message.channel.send({
                embed: {
                    color: '1DB954',
                    title: `${msgMention.displayName} is listening to ${mp.assets.largeText} for some reason`,
                    image: {
                        url: `https://i.scdn.co/image/${imgvar}`
                    },
                },
            });
        } else if (mp.name == "League of Legends") {
            const n = new Date();
            console.log(n)
            const g = mp.timestamps.start;
            if (g <= 0) {
                return;
            }
            const hours = Math.abs(n - g) / 36e5;
            const minutes = hours.toFixed(2)
            message.channel.send(`${msgMention.displayName} has been wasting his life playing ${mp.name} for ${minutes} hours`);
        } else {
            const n = new Date();
            console.log(n)
            const g = mp.timestamps.start;
            if (g <= 0) {
                return;
            }
            const hours = Math.abs(n - g) / 36e5;
            const minutes = hours.toFixed(2)
            message.channel.send(`${msgMention.displayName} has been playing ${mp.name} for ${minutes} hours`);
        }
    },
};

The math works calculating time, along with the seperate spotify command working as well, but league of legends simply doesnt work due to it having rich prescence support, how can I fix this error to reference it for normal non-rich presence games while Rich prescence games still grab the name of the activity

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

0

User activity

  let member = message.mentions.members.first() || message.guild.members.cache.get(args[1]) || message.guild.member(message.author)
  const embed = new Discord.MessageEmbed()

if (!member.presence.activities || member.presence.activities.length == 0) {
    embed.addField('⚽️ Activity:', 'Not playing anything')
} else {
    const activity = member.presence.activities[0];
    embed.addField('⚽️ Activity:', `${activity.type} ${activity.name}\n${activity.details}\n${activity.state}`);
}
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