Skip to content

Room and eventsRoom

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()

method
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

idnumberrequired
Player ID.
mutedbooleanrequired
true to mute, false to unmute.

Returns

Promise<void>

JavaScript
await room.setPlayerMuted(player.id, true);

kickPlayer()

method
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

idnumberrequired
Player ID.
reasonstring
Shown to the player, up to 100 characters. Defaults to Removed by host.
banboolean
true to also ban the player from rejoining this room.

Returns

Promise<void>

JavaScript
await room.kickPlayer(
  player.id,
  'Spamming the chat',
  true,
);

clearBan()

method
room.clearBan(id: number): Promise<void>

Lifts one ban placed by this room. Unknown IDs do nothing.

Parameters

idnumberrequired
The ID the player had when you banned them.

Returns

Promise<void>

JavaScript
await room.clearBan(bannedId);

clearBans()

method
room.clearBans(): Promise<void>

Lifts every ban in the room.

Returns

Promise<void>

Joining

setPassword()

method
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

passwordstring | nullrequired
Up to 64 characters, or null or "" to remove the password.

Returns

Promise<void>

JavaScript
await room.setPassword('derby-night');
await room.setPassword(null); // open again

requireVerification

property
room.requireVerification: boolean | null
readonly

Whether 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()

method
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

requiredbooleanrequired
true to require verification from players who join from now on.

Returns

Promise<void>

JavaScript
await room.setRequireVerification(true);