Multiple type definitions for Cmdr command argument?

  1. What do you want to achieve? I have made a ban system for my game using Cmdr that has a command called “ban”. I want this command to have an argument that can either be a player object (to ban players in your current server), or a number (UserID). Players should still be the autocomplete option, if possible.

  2. What is the issue? I can’t assign multiple types to my Cmdr argument for this command.

  3. What solutions have you tried so far? I haven’t found a way to solve this online, either on the cmdr API pages or on the DevForum

Here's my current ban command file:
return {
    Name = "ban",
    Aliases = {},
    Description = "Bans the given player from the game",
    Group = "Admin",
    Args  = {
        {
            Type = "player";
            Name = "Player";
            Description = "The Player to ban"
        },
        {
            Type = "number";
            Name = "Time";
            Description = "A time in seconds to ban for. (If not provided, set to forever)";
            Default = true;
        },
    }
}

Thanks! :smiley:

1 Like

Could you also put the server script? It relies on the server script too.

you can do it like this:

	{
		Type = "string # number @ player",
		Name = "target",
		Description = ""
	},

Player Example:


UserId:

Player Name:

And then just check the argument type

Example:

-- SERVICES --
local Players = game:GetService("Players")

return function(context, target: string | Player | number, duration: number, displayReason: string, privateReason: string, banAlts: boolean): string
	local TargetType = typeof(target)
	local UserId = TargetType == "number" and target or TargetType == "string" and Players:GetUserIdFromNameAsync(target) or (TargetType == "Instance" and target:IsA("Player")) and target.UserId
	if not UserId then
		return `Failed to ban {target}`
	end
	
	Players:BanAsync({
		UserIds = { UserId },
		Duration = duration,
		DisplayReason = displayReason,
		PrivateReason = privateReason or displayReason,
		ExcludeAltAccounts = not banAlts,
		ApplyToUniverse = true,
	})
	
	return `Successfully banned {target} {UserId}`
end
1 Like