Skip to main content
Version: v2.10.5

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.