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

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

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