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

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

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