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

90
Vistas
Filtering for activity with certain property

In discordjs, I'm trying to read a users presence and then do "If one of presences stated (A user can have Spotify and a game simultaneously as an example) has a name of, say Spotify, in it's properties, do something". My code is:

let uset = msgMention.presence.activities
if (uset.filter(game => game.name == 'Spotify')){
     //something
}

Since multiple games return multiple items in an array (seen below)

[
  Activity {
    name: 'Spotify',
    type: 'LISTENING',
    url: null,
    details: null,
    state: 'NO',
    applicationID: 'NO',
    timestamps: no,
    party: null,
    assets: RichPresenceAssets {
      largeText: null,
      smallText: null,
      largeImage: 'no',
      smallImage: null
    },
    syncID: no,
    flags: ActivityFlags { bitfield: 1 },
    emoji: null,
    createdTimestamp: no
  },
  Activity {
    name: 'Visual Studio Code',
    type: 'PLAYING',
    url: null,
    details: 'Editing league.js',
    state: 'Workspace: Vibin-Tachanks',
    applicationID: '383226320970055681',
    timestamps: { start: 2021-12-04T18:35:34.918Z, end: null },
    party: null,
    assets: RichPresenceAssets {
      largeText: 'Editing a JAVASCRIPT file',
      smallText: 'Visual Studio Code',
      largeImage: '808841241142755358',
      smallImage: '565945770067623946'
    },
    syncID: undefined,
    flags: ActivityFlags { bitfield: 0 },
    emoji: null,
    createdTimestamp: 1638645018501
  }
]

how can I make this if statement work to filter out this returned array and only keep Spotify in it, and then access the name (or any property) of said filtered item. yes, i do have detecting presences working with intents and such so I know I've gotten that far, it's just filtering with an if (Also no just means I dont want to show whats in it)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could just use this filter that you used inside a variable and as the condition of the if statement you could just check if it's different than empty array "[]".

Doing this way you can use the values inside the variable if you have any.

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