harsh Posted January 7, 2022 Report Posted January 7, 2022 What will be the best way to get friend list with steam id? client.on('friendsList', async function () { var friends=[]; async function getAllFriends(){ var temp = []; for (var key in client.myFriends) temp.push(key); return temp; } friends = await getAllFriends(); console.log("[Steam Bot] All Friends: "+friends.length); }); OR Using WebAPI https://api.steampowered.com/ISteamUser/GetFriendList/v1/?key=XXXXXXXXXXXXXXXXXXXX&steamid=76561198872686120 Quote
Dr. McKay Posted January 8, 2022 Report Posted January 8, 2022 If you're trying to get your own friends list and you're already using steam-user for other things, then you might as well just use steam-user for that. Although your code can be simplified to: client.on('friendsList', function() { let friends = Object.keys(client.myFriends.filter(relationship => SteamUser.EFriendRelationship.Friend)); console.log('All Friends: ' + friends.length); }); Your code as written will also include people who you've sent a friend request to, people who've sent a request to you, and blocked users as friends. If you're not already using some other feature in steam-user, then it'd be easier to just use the WebAPI. And if you're trying to get someone else's friends list, you'll have to use the WebAPI. Quote
harsh Posted January 8, 2022 Author Report Posted January 8, 2022 thanks for update, your code have small typo. fixed:- client.on('friendsList', function() { let friends = Object.keys(client.myFriends).filter(relationship => SteamUser.EFriendRelationship.Friend); console.log('All Friends: ' + friends.length); }); Quote
Dr. McKay Posted January 9, 2022 Report Posted January 9, 2022 Ah yeah, there is a problem, but your fix doesn't properly fix it. Here's the proper fix: client.on('friendsList', function() { let friends = Object.keys(client.myFriends).filter(steamId => client.myFriends[steamId] == SteamUser.EFriendRelationship.Friend)); console.log('All Friends: ' + friends.length); }); 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.