Skip to content

server.detached

Runs work that belongs to the whole server rather than to one player. Normally, timers and promises a handler starts stop when the player whose event or command it was leaves (see async handlers). Inside server.detached they run on until your gamemode stops, so a round an admin started goes on when the admin leaves.

server.detached<T>(callback: () => T): T
Name Type Description
callback () => T The work. It runs at once.

What callback returns, unchanged; a promise is not awaited for you, and its errors are yours to catch.

gamemodes/my-mode.ts
import { chat, commands, server } from "nativemp";
commands.register("startround", () => server.detached(() => {
const timer = setInterval(() => chat.sendServerMessage("Round tick"), 1000);
setTimeout(() => clearInterval(timer), 60_000);
}));