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

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

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