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.
Signature
Section titled “Signature”players.banAddress(player: PlayerTarget, reason?: string, expiresAtUnixSeconds?: number | null): Promise<ActionResult>Parameters
Section titled “Parameters”| 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. |
Returns
Section titled “Returns”A promise of an ActionResult: applied once the ban is saved and the player disconnected.
Example
Section titled “Example”A /tempban for a day.
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.Related
Section titled “Related”bans.list: every active banbans.remove: lift oneplayerConnectRequest:addressis what a ban matches
A captured Player keeps this effect bound to its connection across awaits; see Async handlers.