Rules Posted July 1, 2018 Report Posted July 1, 2018 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 sID = STEAMIDHERE 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: console.log(rPresence.status); 'Playing CS:GO' Thanks in advance!Sorry in advance if I this is very trivial. Quote
Dr. McKay Posted July 1, 2018 Report Posted July 1, 2018 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 Rules 1 Quote
Rules Posted July 7, 2018 Author Report Posted July 7, 2018 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 Dr. McKay 1 Quote
Recommended Posts
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.