Ban API method for retrieving the ban status of a user

As a Roblox developer, it is currently too hard to retrieve the current ban status of a user using the new ban API.

Currently, you have to do this in order to get the ban status of a player:

local banStatus = Players:GetBanHistoryAsync(123456789):GetCurrentPage()[1]

While this works and can be done on a single line, it’s a bit confusing looking at it, no? I suppose I understand why the BanHistoryPages object was created, but calling a method that returns a table with just one element and having to index the first element of that table in order to get the ban action dictionary is a bit odd.

It would be nice if we could do something like this:

local banStatus = Players:GetBanStatusAsync(123456789)

Where a method returns a dictionary representing the most recent ban action taken on this user.

Use cases:

  1. Let’s say a moderator is trying to unban someone, but we only want moderators to be able to remove temporary bans, and need to do a quick check on the Duration field of their most recent ban action dictionary.
  2. Let’s also say a moderator is trying to temporarily ban someone but we do not want them to be able to overwrite any permanent bans. A simple check for their ban duration would also be nice in this scenario.

I’m not entirely sure whether a method like this would be more performant for use cases like these, but my main reason for requesting this is that it’d improve readability in my code if I’m just trying to get the ban status of a player, and am not interested in the entire ban history of the player.

12 Likes

I was just replacing my existing ban implementation with the new APIs, when I realized there was no way to make a command check if a player is already banned.

This feature is much needed, or at least documentation detailing how to achieve this.

5 Likes

Support for ergonomics, although I would clarify the name to GetCurrentBanStatusAsync.

I would rather not have to do this:

type BanStatus = {
	DisplayReason: string,
	PrivateReason: string,
	StartTime: string,
	Duration: number,
	Ban: boolean,
	PlaceId: number
}

local function GetCurrentUserBanStatus(UserId: number): BanStatus?
	local Success, Pages = pcall(Players.GetBanHistoryAsync, Players, UserId)
	
	if Success then
		return Pages:GetCurrentPage()[1]
	end
	
	return nil
end

local function GetIsUserCurrentlyBanned(UserId: number): boolean
	local CurrentBanStatus = GetCurrentUserBanStatus(UserId)
	
	if CurrentBanStatus then
		return CurrentBanStatus.Ban
	end
	
	return false
end
3 Likes

4 Months later, still nothing.