7 sdk/js/player/query
Braydon edited this page 2024-04-15 13:00:51 -07:00

Query Player

Example

import {
	getPlayer,
	type CachedPlayer,
	type RestfulMCAPIError,
} from "restfulmc-lib";

try {
	const player: CachedPlayer = await getPlayer("Rainnny");
	console.log(`Hello ${player.username}, your UUID is ${player.uniqueId}!`);
} catch (err) {
	if ((err as RestfulMCAPIError).code == 404) {
		console.error("Player with UUID or username not found.");
	}
}

Output

$ bun index.ts 
Hello Rainnny, your UUID is fc1d5fe7-f29b-430d-80bb-3b093a638b0f!