Moderation
Mute, kick and ban players, and control who can join.
Bans, passwords and join verification are enforced by the Ball2D service, so these commands wait for its confirmation and reject if the service does not confirm.
Players
setPlayerMuted()
room.setPlayerMuted(id: number, muted: boolean): Promise<void>Mute room chat for this player until unmuted or they leave.
A muted player cannot send room chat, direct messages or typing indicators, and their messages never reach onPlayerChat. The mute lasts until you lift it or the player leaves; use a ban to keep someone out. The host player cannot be muted. Fires onPlayerMuteChange.
Parameters
numberrequiredbooleanrequiredtrue to mute, false to unmute.Returns
Promise<void>
await room.setPlayerMuted(player.id, true);kickPlayer()
room.kickPlayer(id: number, reason?: string, ban?: boolean): Promise<void>Removes a player. onPlayerLeave fires, then onPlayerKicked. The host player and unknown IDs are ignored.
A ban is stored by the service against the player's network address and applies for the life of this room, up to 256 bans. The command rejects, and the player stays, if the service cannot confirm the ban within 10 seconds.
Parameters
numberrequiredstringRemoved by host.booleantrue to also ban the player from rejoining this room.Returns
Promise<void>
await room.kickPlayer(
player.id,
'Spamming the chat',
true,
);clearBan()
room.clearBan(id: number): Promise<void>Lifts one ban placed by this room. Unknown IDs do nothing.
Parameters
numberrequiredReturns
Promise<void>
await room.clearBan(bannedId);clearBans()
room.clearBans(): Promise<void>Lifts every ban in the room.
Returns
Promise<void>
Joining
setPassword()
room.setPassword(password: string | null): Promise<void>Players who join after the change need the new password; players already in the room stay. The service limits how often a room can change its password; a rejection such as Password update limit. Try later. means you should wait before trying again.
Parameters
string | nullrequirednull or "" to remove the password.Returns
Promise<void>
await room.setPassword('derby-night');
await room.setPassword(null); // open againrequireVerification
room.requireVerification: boolean | nullWhether joining players must pass a human verification challenge. null before the room is admitted, after it closes, or while the result of an update is unknown.
setRequireVerification()
room.setRequireVerification(required: boolean): Promise<void>Adds a human verification challenge to joining, which slows automated joins. It rejects with Room verification is not configured on this server. on a service that does not offer verification.
Parameters
booleanrequiredtrue to require verification from players who join from now on.Returns
Promise<void>
await room.setRequireVerification(true);