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

130
Visualizações
discord auto role when status matches

Ive tries some different things to make this work but it's not wanting to work

so am basicly trying to check someones custom status for a specific thing if there is for example .gg/test in it and give them a role than

My code


client.on('presenceUpdate', async (oldPresence, newPresence) => {
  const role = newPresence.guild.roles.cache.get("927284722059595828");
  const member = newPresence.member
  const activities = member.user.presence.activities[0];

  if (activities && (activities.state.includes( ".gg/test" ) || activities.state.includes("discord.gg/test" ))) {
    return newPresence.member.roles.add(role)
  } else {
    if(member.roles.cache.get(role.id)) {
      newPresence.member.roles.remove(role)
    }
  }
})

so can anyone correct the code to the correct format

and if possable make this multi server usable with a command thanks

the error i get

TypeError: Cannot read properties of undefined (reading 'id')
    at Client.<anonymous> (/root/raegay2/boy.js:19:36)
    at Client.emit (node:events:390:28)
    at PresenceUpdateAction.handle (/root/raegay2/node_modules/discord.js/src/client/actions/PresenceUpdate.js:39:19)
    at Object.module.exports [as PRESENCE_UPDATE] (/root/raegay2/node_modules/discord.js/src/client/websocket/handlers/PRESENCE_UPDATE.js:4:33)
    at WebSocketManager.handlePacket (/root/raegay2/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
    at WebSocketShard.onPacket (/root/raegay2/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/root/raegay2/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/root/raegay2/node_modules/ws/lib/event-target.js:132:16)
    at WebSocket.emit (node:events:390:28)
    at Receiver.receiverOnMessage (/root/raegay2/node_modules/ws/lib/websocket.js:825:20)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I just tested your code and it worked fine. Did you enable Presence Intent on your bots discord developer page? If you are using Gateway Intents, you must specify the GUILD_PRESENCES intent in order to receive Presence Update events.

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