How to get all players in a group?

So I want to get all the players in the group for something I want to do but I can’t seem to find how to do this anywhere. Does anyone know how to do this?

2 Likes

Can’t do it with Roblox API but you can check if a player in the game is in the group using some player API functions like player:IsInGroup() and you can use GroupsService for players not in the game.

A very roundabout way of doing this would be having either a requirement for people to join the group (For example they have to join a place for Verification, and this place logs that user joining in a datastore) or you could have a Bot set up for that group which gets every player. < using noblox noblox.js Home. Other than that I am unaware of any other methods which would allow you to get every single player within a group.

1 Like

But I want to get all the players in a group even if they are not in the game

That just wouldn’t be possible given the Roblox API.

found this https://groups.roblox.com/v1/groups/6467229/roles/41631558/users?cursor=&limit=50&sortOrder=Desc, first number is probably group id and second is role id?


if you are curious on how i found it, it was by using the Network tab in developer tools:

4 Likes

HTTP Request: https://groups.roblox.com/v1/groups/GroupId/users?sortOrder=Asc&limit=100

However you cannot do this from Roblox, you must use a proxy/webserver due to limitations on HttpService.
image

You’d need to keep looping until nextPageCursor is null to have all the members.

2 Likes

The group has more than 100 members and it doesn’t display the roles I need, I need it to display the higher roles rather than the members

1 Like

100 is the limit it returns per page, not only 100 overall.

You’d need to use if checks to determine their rank.

Loop and break the loop once nextPageCursor is null. Add each username/id entry into an array then send it back to the game. The returned object will be a list of each name/id depending which you choose.

What it Returns (hidden so it doesn't flood)
{
   "previousPageCursor":null,
   "nextPageCursor":null,
   "data":[
      {
         "user":{
            "buildersClubMembershipType":"None",
            "userId":1526798957,
            "username":"Rileythegamercool",
            "displayName":"Rileythegamercool"
         },
         "role":{
            "id":33811880,
            "name":"Member",
            "rank":1,
            "memberCount":3
         }
      },
      {
         "user":{
            "buildersClubMembershipType":"None",
            "userId":464804960,
            "username":"Noble_theSwift",
            "displayName":"Noble_theSwift"
         },
         "role":{
            "id":33811880,
            "name":"Member",
            "rank":1,
            "memberCount":3
         }
      },
      {
         "user":{
            "buildersClubMembershipType":"None",
            "userId":1224351089,
            "username":"vishnucr77",
            "displayName":"vishnucr77"
         },
         "role":{
            "id":33811880,
            "name":"Member",
            "rank":1,
            "memberCount":3
         }
      },
      {
         "user":{
            "buildersClubMembershipType":"None",
            "userId":113430644,
            "username":"phoenixcards1234",
            "displayName":"phoenixcards1234"
         },
         "role":{
            "id":33811935,
            "name":"Trainee",
            "rank":2,
            "memberCount":1
         }
      },
      {
         "user":{
            "buildersClubMembershipType":"None",
            "userId":201989656,
            "username":"iiRealistic_Dev",
            "displayName":"iiRealistic_Dev"
         },
         "role":{
            "id":33811879,
            "name":"Assistant Director",
            "rank":6,
            "memberCount":1
         }
      },
      {
         "user":{
            "buildersClubMembershipType":"None",
            "userId":656842840,
            "username":"BakDoor",
            "displayName":"BakDoor"
         },
         "role":{
            "id":33811878,
            "name":"Director",
            "rank":255,
            "memberCount":1
         }
      }
   ]
}
2 Likes

How would I take it to the next page?

2 Likes

The URL on groups.roblox.com

https://groups.roblox.com/v1/groups/{GroupId}/users?sortOrder=Asc&limit=10&cursor={ReturnedNextPageCursor}

6 Likes

So I used this script

local HttpService = game:GetService("HttpService")

local URL = "https://groups.roblox.com/v1/groups/6094444/users?sortOrder=Asc&limit=100"

local data
local response
 
local function printData()
	pcall(function ()
		response = HttpService:GetAsync(URL)
		data = HttpService:JSONDecode(response)
	end)
	return true
end
 
if printData() then
	print(data)
	print(response)
else
	print("Something went wrong")
end

But both of the values keep returning false

1 Like

You will need a proxy server to make the requests to Roblox. HttpService will not allow you to make any requests to a Roblox-owned domain.

1 Like

Is there a way to automate this? I know how to get the nextcursor page but it’s tiring to do this when I have to do it for groups with 20k members

Sorry for a late reply - haven’t been on DevForum in a while.

You probably figured something out by now - but if not the best thing I can think of is using a while loop and just sending the request over until nextPageCursor is null.

For example, in JavaScript

const baseUrl = "https://groups.roblox.com/v1/groups/{GroupId}/users?sortOrder=Asc&limit=10"

async function allMembers() {
  const members = []
  let res = await fetch(baseUrl).json()
  res.data.forEach(member => members.push(member))
  while (res.nextPageCursor) {
    res = await fetch(`${baseUrl}&cursor=${res.nextPageCursor}`).json()
    res.data.forEach(member => members.push(member))
  }
  return members
}

async function main() {
  const groupMembers = await allMembers()
  // do something here
}

main()

I haven’t tested this and only wrote it out just now without a text editor/IDE so it may be slightly buggy or spellings might be wrong, but hopefully you get the idea. If the members array is repeatedly empty, given the use of async-await instead of using forEach try using for (const member of res.data) { /* code here */ }to add them to the members array.

If your group has 20k members, however, you may want to look into pausing between requests to avoid ratelimiting.