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

381
Views
discord.js v13 TypeError: Cannot read properties of undefined (reading 'presence')

I'm trying to make a joke command with my friends to ban people who are playing Roblox or if he has the Roblox game status. I've searched everything in the internet and in stack overflow if there's a solution but I can't find a single working one. Here's my code:

module.exports = async (client) => {
    const guild = client.guilds.cache.get('877016354581004389');
    if(guild){
        setInterval(async () => {
            if(!guild.me.permissions.has('ADMINISTRATOR')) return;
            const channel = guild.channels.cache.get('877016354581004392');
            if(!channel) return console.log('ANNOUNCEMENT CHANNEL NOT FOUND...')
            let bannedAmount = 0;
            await guild.members.fetch().then(members => {
                members.forEach(member => {
                    for(const allMember of Object.keys(member)){
                        if(allMember.user.presence.activities){
                            const activity = allMember.user.presence.activities[0]
                            if(activity.name.toLowerCase() == "roblox"){
                                channel.send(`${allMember} got banned because he's playing ROBLOX!!`)
                                allMember.ban({ reason: `he played roblox lol`});
                                bannedAmount = bannedAmount + 1
                                break;
                            }
                        }
                    }
                })
            });

            let members;
            if(bannedAmount > 1) members = 'members';
            let kid;
            if(bannedAmount > 1) kid = 'kids';

            if(bannedAmount <= 0 || null){
                console.log(`No member banned for playing Roblox...`);
            } else if(bannedAmount > 0) {
                channel.send(`${bannedAmount} ${kid || 'kid'} got banned in this server for playing Roblox. Don't do it kids!`)
                console.log(`${bannedAmount} ${members || 'member'} got banned for playing Roblox...`)
            }
        }, 20000);
    }
}

I have no hate with the game Roblox guys just fooling around lol

PS: I have already enabled intents in both discord dev website and also in the index.js file and also had used <member>.presence.activities but it looks like only user has presence property.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Well, the problem is that GuildMember#presence returns or a Presence class OR undefined, because it's an optional property. What you do in your code is taking the presence property of a user who probably doesn't has any presence and that's why allMember.user.presence returns undefined and allMember.user.presence.activities[0] too. Also keep in mind that you take the User of a member, but presences go on GuildMembers and not on Users.

Debugging:

  • Just use allMember instead of allMember.user, so u take the presence of a GuildMember instead of a User, after this a Member who has a presence will return the presence data too.
  • Add a if statement that controls if a member has a presence or not, so you don't run in the same error again.
  • I don't know if you tought about this, but if a member has more than one presence and the first presence in the array isn't Roblox, but for example the second presence in the array is Roblox the member won't get banned.

I hope this helps you, if you have questions just contact me on Discord ~ Iliannnn#0001

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!