Skip to main content
Version: v2.10.1

Manager

Table of Contentsโ€‹

Class Definitionโ€‹

export class Manager extends EventEmitter {}

Propertiesโ€‹

Property Type Description
initiatedbooleanWhether the manager has been initiated.
nodesCollection<string, Node>The nodes.
optionsManagerOptionsThe manager options.
playersCollection<string, Player>The players.
redis?RedisClientThe Redis client.

Constructorโ€‹

new Manager(options: ManagerOptions)
Parameter Type Description Optional
optionsManagerOptionsThe manager options.

Methodsโ€‹

cleanupInactivePlayer()โ€‹

async cleanupInactivePlayer(guildId: string): Promise<void>

Cleans up an inactive player by removing its stored state data. Supports JSON and Redis storage backends.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.

create()โ€‹

create(options: PlayerOptions): Player

Creates a player, or returns the existing one if a player for the given guild already exists.

Parametersโ€‹

Parameter Type Description Optional
optionsPlayerOptionsThe player options.

Returnsโ€‹

Type Description
PlayerThe new or existing player.

createNode()โ€‹

createNode(options: NodeOptions): Node

Creates a node, or returns the existing one if a node with the given identifier already exists.

Parametersโ€‹

Parameter Type Description Optional
optionsNodeOptionsThe node options.

Returnsโ€‹

Type Description
NodeThe new or existing node.

decodeTrack()โ€‹

async decodeTrack(track: string): Promise<TrackData>

Decodes a single base64 encoded track.

Parametersโ€‹

Parameter Type Description Optional
trackstringThe base64 encoded track.

Returnsโ€‹

Type Description
Promise<TrackData>The decoded track.

decodeTracks()โ€‹

async decodeTracks(tracks: string[]): Promise<TrackData[]>

Decodes multiple base64 encoded tracks.

Parametersโ€‹

Parameter Type Description Optional
tracksstring[]An array of base64 encoded tracks.

Returnsโ€‹

Type Description
Promise<TrackData[]>The decoded tracks.

destroy()โ€‹

async destroy(guildId: string): Promise<void>

Destroys a player.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.

destroyNode()โ€‹

async destroyNode(identifier: string): Promise<void>

Destroys a node. Throws a MagmaStreamError if the node does not exist.

Parametersโ€‹

Parameter Type Description Optional
identifierstringThe node identifier.

getPlayer()โ€‹

getPlayer(guildId: string): Player | undefined

Returns a player, or undefined if no player exists for the given guild.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.

Returnsโ€‹

Type Description
Player | undefinedThe player, or undefined.

handleShutdown()โ€‹

async handleShutdown(): Promise<void>

Handles a graceful shutdown by saving all active player states, unloading plugins, and exiting the process. Called automatically on SIGINT / SIGTERM when listenToSIGEvents is enabled.


init()โ€‹

async init(options?: ManagerInitOptions): Promise<this>

Initializes the manager, connects all nodes, and loads plugins. Returns immediately if already initiated.

Parametersโ€‹

Parameter Type Description Optional
optionsManagerInitOptionsThe manager init options.

Returnsโ€‹

Type Description
Promise<this>The manager instance.

loadPlayerStates()โ€‹

async loadPlayerStates(nodeId: string): Promise<void>

Loads and restores persisted player states for the given node. Supports Memory, JSON, and Redis storage backends.

Parametersโ€‹

Parameter Type Description Optional
nodeIdstringThe node identifier.

on()โ€‹

on<T extends keyof ManagerEvents>(event: T, listener: (...args: ManagerEvents[T]) => void): this

Attaches an event listener to the manager.

Parametersโ€‹

Parameter Type Description Optional
eventT extends keyof DebugEvent | LyricsEvent | NodeEvents | PlayerEvents | SponsorBlockEvents | TrackEvents | VoiceReceiverEventsThe event name.
listener(...args: any[]) => voidThe event listener.

resolveGuild()โ€‹

resolveGuild(guildId: string): AnyGuild

Resolves a guild ID to a guild object using the getGuild cache callback, or returns null if unresolvable. Can be overridden by wrapper managers to return wrapper-specific guild types.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.

Returnsโ€‹

Type Description
AnyGuildThe resolved guild, or null.

resolveUser()โ€‹

async resolveUser(user: AnyUser | string): Promise<AnyUser>

Resolves a user object or ID to an AnyUser. Can be overridden by wrapper managers to return wrapper-specific user types.

Parametersโ€‹

Parameter Type Description Optional
userAnyUser | stringThe user object or ID.

Returnsโ€‹

Type Description
Promise<AnyUser>The resolved user.

savePlayerState()โ€‹

async savePlayerState(guildId: string): Promise<void>

Serializes and persists the state of a player to the configured storage backend. Skips players that are disconnected or have no active voice channel.

Parametersโ€‹

Parameter Type Description Optional
guildIdstringThe guild ID.

async search<T = unknown>(query: string | SearchQuery, requester?: T): Promise<SearchResult>

Searches for tracks using the configured default search platform, or a URL directly.

Parametersโ€‹

Parameter Type Description Optional
querystring | SearchQueryThe search query or URL.
requesterT = unknownThe user who requested the search.

send()โ€‹

warning

This method is protected and should not be called directly. Use sendPacket() instead.

protected send(packet: GatewayVoiceStateUpdate): unknown

Sends a voice state update packet to the Discord gateway via the configured send callback.

Parametersโ€‹

Parameter Type Description Optional
packetGatewayVoiceStateUpdateThe gateway packet.

sendPacket()โ€‹

sendPacket(packet: GatewayVoiceStateUpdate): unknown

Public proxy for send(). Sends a voice state update packet to the Discord gateway.

Parametersโ€‹

Parameter Type Description Optional
packetGatewayVoiceStateUpdateThe gateway packet.

updateVoiceState()โ€‹

async updateVoiceState(data: VoicePacket | VoiceServer | DiscordVoiceState): Promise<void>

Processes an incoming Discord voice packet and updates the relevant player's voice state accordingly.

Parametersโ€‹

Parameter Type Description Optional
dataVoicePacket | VoiceServer | DiscordVoiceStateThe raw voice data.

useableNode()โ€‹

get useableNode(): Node

Returns the most suitable node based on the configured useNode and enablePriorityMode options.

Returnsโ€‹

Type Description
NodeThe selected node.