2021-12-05

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)



from Recent Questions - Stack Overflow https://ift.tt/3xVZp8b
https://ift.tt/eA8V8J

No comments:

Post a Comment