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

383
Vistas
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 Respuestas
Responde la pregunta

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