Skip to content

players.banAddress

Bans the address a player connects from and disconnects them. Their launcher shows Banned: and your reason. The server saves bans, so they survive a restart.

Renamed in 0.28 from players.ban; see renamed names.

players.banAddress(player: PlayerTarget, reason?: string, expiresAtUnixSeconds?: number | null): Promise<ActionResult>
Name Type Description
player PlayerTarget The player, or their ID.
reason string Optional. Valid UTF-8 without control characters, cut to 128 bytes. Defaults to Banned by the server.
expiresAtUnixSeconds number | null Optional. When the ban ends, in Unix seconds; must be in the future. null (the default) bans for good.

A promise of an ActionResult: applied once the ban is saved and the player disconnected.

A /tempban for a day.

gamemodes/admin.ts
import { chat, commands, players } from "nativemp";
const day = 24 * 60 * 60;
commands.register("tempban", async (player, args) => {
const [id, ...reason] = args.trim().split(" ");
const result = await players.banAddress(Number(id), reason.join(" ") || undefined, Math.floor(Date.now() / 1000) + day);
if (result.status === "rejected") chat.sendServerMessage(`Ban failed: ${result.code}`, player);
}, { authorize: (player) => player.id === 1 }); // Replace with the mode's role lookup.

A captured Player keeps this effect bound to its connection across awaits; see Async handlers.