Checking if multiple users are banned through UserService

Hello, this topic demonstrates a method of checking if multiple user ids are banned or not through UserService. More specifically, it takes advantage of the fact that the API call GetUserInfosByUserIdsAsync doesn’t return info for banned users.

Here’s the code:

local UserService = game:GetService("UserService")

--max amount of accepted ids per batch: 200
return function(userIds: {number}): {number}
	local response = UserService:GetUserInfosByUserIdsAsync(userIds)
	local bannedAccounts = table.clone(userIds) 
	for _, info in pairs(response) do
		local index = table.find(bannedAccounts, info.Id)
		if index then table.remove(bannedAccounts, index) end
	end
	return bannedAccounts
end

It’s really simple in nature, it just assumes all users are banned at first and for each user the API call returns removes them from the banned table. That way only the users that aren’t returned remain in the final table and thus the banned ones.

Here’s how you can use it(make it a module):

local getBannedAccounts = require(script.ModuleScript)

--example userIds input
local userIds = {}
for i = 1, 200 do table.insert(userIds, i) end

--should print all the banned userIds up to 200
print(getBannedAccounts(userIds))

The code can error if Roblox raises an API call error(such as a 429 rate limit error), if you want to avoid that you can wrap the getBannedAccounts method in a pcall and handle the error yourself.

That API works with batches of max size 200, so if you want to check more user ids, you will have to break them into 200 user id segments and pass them segment by segment in the function.

2 Likes