I am creating an event to identify the Member Status

Viewed 51
client.on('raw', async dados => {
  if(dados.t == 'PRESENCE_UPDATE' && this.client.guilds.cache.get("948835296089342012").members.cache.get(dados.d.user.id)){
    let membro = this.client.guilds.cache.get("948835296089342012").members.cache.get(dados.d.user.id)

    if(dados.d.activites.state == null) return membro.roles.remove("653651520361070612")
    if(dados.d.activities.state == undefined) return membro.roles.remove("653651520361070612")

    let valor = dados.d.activities.state.toLowerCase()
    let n = valor.search(`discord.gg/server`)
    
    if(n>=0) membro.roles.add("653651520361070612")
    if(n<0 && membro.roles.cache.has("653651520361070612")) membro.roles.remove("653651520361070612")

  }

log=

user: { id: '932194344859996180' },
  status: 'online',
  guild_id: '947899731303096320',
  client_status: { web: 'online' },
  activities: [
    {
      type: 4,
      state: 'aa536a43',
      name: 'Custom Status',
      id: 'custom',
      created_at: 1647655901662
    }
  ]
}

I'm creating an event to identify the member's Status, for example: if the member has the url in the discord.gg/3 status the member will receive a position and when he removes the status the bot will remove the selected position

2 Answers
const Command = require("../../structures/Command");


module.exports = class teste extends Command {
  constructor(client) {
    super(client);
    this.client = client;

    this.name = "teste";
    this.category = "Fun";
    this.description = ".";
    this.usage = "";
    this.aliases = [];

    this.enabled = true;
    this.guildOnly = true;
  }
  async run({ message, args}, t) {

  const user = 
    this.client.users.cache.get(args[0]) ||
      message.mentions.members.first() ||
      message.author

  console.log(user.presence.activities.state)

}
}

I also tried to use this without being on the basis of the Event but on the command, it always returns undefined

log=

[
  Activity {
    id: 'custom',
    type: 'CUSTOM',
    url: null,
    details: null,
    state: 'aa536a43',
    applicationId: null,
    syncId: null,
    platform: null,
    party: null,
    assets: null,
    flags: ActivityFlags { bitfield: 0 },
    emoji: null,
    sessionId: null,
    buttons: [],
    createdTimestamp: 1647656752595
  }
]

The presence is only available on GuildMember not an user. Get the member who used the command from message.member (make sure that the command is used in a guild)
Now read the member's presence through message.member.presence. Seems like you are trying to get member's custom status. It's one of presence.activities array and has the type Activity. Find in that array which has the type is CUSTOM, that is what you need. Note that presence can be null so you need to check if it exists.
This is the code I have tested and it works. Hope it works for you too:

const member = message.member; // Get member from message
const custom = member.presence?.activities?.find(x => x?.type === 'CUSTOM'); // Get the custom status from member's presence
if (custom?.includes('cat') console.log('This user has `cat` in his/her custom status');
else { console.log('This user doesn\'t have `cat` in his/her custom status'); }
Related