Jump to content
McKay Development

best way to get friend list?


harsh
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
});

 

Link to comment
Share on other sites

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);
});

 

Link to comment
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.

Guest
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.

Loading...
 Share

×
×
  • Create New...