Getting Multiple Groups with the Groups API in Javascript

I have this script currently:

function check() {
    membercounter.find((err, documents) => {
        if (err) return console.log(err)
        documents.forEach(async (doc, i) => {
            setTimeout(async function() {
                let response = await axios.get(`https://groups.roblox.com/v1/groups/${doc.groupid}/`)
                let response_count = response.data.memberCount
                if (doc.currentCount === null) {
                    membercounter.findOneAndUpdate({ groupid: response.data.id }, { currentCount: response_count }, function(err, doc, res) {
                        
                    })
                    return
                }
                if (doc.currentCount < response_count || doc.currentCount > response_count) {
                    await axios.post(doc.webhook, { content: ... })
                    if (doc.currentCount === 0) {
                        membercounter.findOneAndUpdate({ groupid: response.data.id }, { currentCount: response_count }, function(err, doc, res) {
                            
                        })
                        return;
                    }
                    
                    membercounter.findOneAndUpdate({ groupid: response.data.id }, { currentCount: response_count }, function(err, doc, res) {
                        
                    })
                }
    
            }, 5000 * i)
        })
    })
}

setInterval(check, 120000)

I’ll explain it –
I’m making a member counter script where it gets the group id, webhook, etc from a MongoDB database using Mongoose. The script should technically work, except I’m getting ratelimited by Roblox, despite having protections in place (2 minute cooldown for checking, takes 5 seconds * index for the web request) yet I still get ratelimited. Is this a code issue, or something with Roblox?

Any help is appreciated.
Thanks!

Depending on how many groups you’re checking, 5000 ms times the index might not be enough time in between checking each group. In my personal experience, the group info endpoint has had an extremely restrictive rate limit in place. In my testing, I’ve only been able to make ~11 calls per minute with the /groups/{groupId} before getting ratelimited. What you could do as an alternative to get around the ratelimits is to use the /groups/groupId/roles endpoint, which has a much less restrictive ratelimit as opposed to the endpoint you’re using to get the member count. This endpoint will return an array of group ranks, with the amount of members each rank has. With that information, you can simply iterate over all the ranks, and add up the memberCount property of each rank.

const groupRolesResponse = await axios.get('https://groups.roblox.com/v1/GROUPID/roles');
const memberCount = groupRolesResponse.roles.reduce((accumulator, value) => accumulator += value.memberCount, 0));

console.log(memberCount);

You don’t have to use .reduce here, it’s just a bit shorter than other ways of doing it. If you’re curious how it works, you can read up on array.reduce here

I’m checking an unknown number of groups, and your code there is irrelevant, memberCount is in the Groups API https://groups.roblox.com/docs#!/Groups/get_v1_groups_groupId

I know you can get the memberCount using that endpoint, I’m saying that the ratelimits on that endpoint are very strict, so I provided an alternative method to get the total number of members in the group that doesn’t have as strict of a ratelimit.

Ohh okay, now I see. I can try that.

1 Like