Jump to content
McKay Development

Parsing Users' Rich Presence

Recommended Posts

This is my first project so I hope this isn't something incredibly nooby. Not familiar with node or Javascript at all.

When pulling a users Rich Presence information via:

let rPresence = sClient.users[sID].rich_presence

Rich Presence seems to be an object of arrays? It is structured as follows:

   [ { key: 'status', value: 'Playing CS:GO' },
     { key: 'version', value: '13638' },
     { key: 'time', value: '18.234842' },
     { key: 'steam_display', value: '#display_Menu' } ]

I suppose my question is how I could parse this information into a single object so I could access information like:


'Playing CS:GO'

Thanks in advance!

Sorry in advance if I this is very trivial.

Share this post

Link to post
Share on other sites

This is incredibly nooby but hey, we all start somewhere, right? Props for wanting to learn and not wanting everything just handed to you.


You'd want to create an object and store it in a variable (e.g. let richPresence = {};), then loop over the array and set properties in that object (using bracket notation). So, this:

let richPresence = {}; // create a new, empty object
(sClient.users[sID].rich_presence || []).forEach((element) => {
	// Loop over the rich_presence array. If it happens to be missing, substitute it using || for
	// an empty array so we don't end up crashing by trying to reference forEach on undefined/null.
	richPresence[element.key] = element.value;

console.log(richPresence.status); // Playing CS:GO

Share this post

Link to post
Share on other sites

I wrote a whole 'lil DiscordJS//steam-user bot to tell the homies the score of the match and then discovered the globaloffensive module. Now I'm delving down the hole of all the information I can retrieve from that. This is quite the learning experience. I really should've started with some Node tutorials  :D  

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...