Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!