Skip to main content
Version: v2.10.1

PlayerUtils

Table of Contentsโ€‹

Class Definitionโ€‹

export abstract class PlayerUtils {}
info

PlayerUtils is an abstract utility class. All members are static โ€” it cannot be instantiated directly.

Methodsโ€‹

getGuildDir()โ€‹

static getGuildDir(guildId: string): string

Returns the absolute path to the JSON storage directory for the given guild. Equivalent to {playersBaseDir}/{guildId}.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.

Returnsโ€‹

Type Description
stringAbsolute path to the guild's data directory.

getPlayerCurrentPath()โ€‹

static getPlayerCurrentPath(guildId: string): string

Returns the absolute path to current.json for the given guild.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.

Returnsโ€‹

Type Description
stringAbsolute path to current.json.

getPlayerPreviousPath()โ€‹

static getPlayerPreviousPath(guildId: string): string

Returns the absolute path to previous.json for the given guild.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.

Returnsโ€‹

Type Description
stringAbsolute path to previous.json.

getPlayerQueuePath()โ€‹

static getPlayerQueuePath(guildId: string): string

Returns the absolute path to queue.json for the given guild.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.

Returnsโ€‹

Type Description
stringAbsolute path to queue.json.

getPlayerStatePath()โ€‹

static getPlayerStatePath(guildId: string): string

Returns the absolute path to state.json for the given guild.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.

Returnsโ€‹

Type Description
stringAbsolute path to state.json.

getPlayersBaseDir()โ€‹

static getPlayersBaseDir(): string

Returns the absolute path to the root directory used by the JSON storage backend: {cwd}/magmastream/sessionData/players.

Returnsโ€‹

Type Description
stringThe base directory for all player data files.

getRedisKey()โ€‹

static getRedisKey(): string

Returns the Redis key prefix used for player storage, derived from stateStorage.redisConfig.prefix. Trailing colons are normalised and a single trailing colon is always appended (e.g. "magmastream:").

Returnsโ€‹

Type Description
stringThe normalised Redis key prefix.

init()โ€‹

static init(manager: Manager): void

Initializes the static Manager reference used by PlayerUtils. Called internally by the manager.

Parametersโ€‹

Parameter Type Description Optional
managerManagerThe Manager instance.

serializePlayer()โ€‹

static async serializePlayer(player: Player): Promise<SerializedPlayerState | null>

Serializes a Player instance into a JSON-safe snapshot, stripping non-serializable values (functions, symbols, Map, Set, sockets, timers, etc.). Returns null if serialization fails.

Parametersโ€‹

Parameter Type Description Optional
playerPlayerThe player to serialize.

Returnsโ€‹

Type Description
Promise<SerializedPlayerState | null>The serialized snapshot, or null on failure.