Table of Contentsโ
export class Manager extends EventEmitter {}
new Manager(options: ManagerOptions)
| Parameter | Type | Description | Optional |
|---|
options | ManagerOptions | The manager options. | |
async cleanupInactivePlayer(guildId: string): Promise<void>
Cleans up an inactive player by removing its stored state data. Supports JSON and Redis storage backends.
| Parameter | Type | Description | Optional |
|---|
guildId | string | The guild ID. | |
create(options: PlayerOptions): Player
Creates a player, or returns the existing one if a player for the given guild already exists.
| Parameter | Type | Description | Optional |
|---|
options | PlayerOptions | The player options. | |
| Type | Description |
|---|
Player | The new or existing player. |
createNode(options: NodeOptions): Node
Creates a node, or returns the existing one if a node with the given identifier already exists.
| Parameter | Type | Description | Optional |
|---|
options | NodeOptions | The node options. | |
| Type | Description |
|---|
Node | The new or existing node. |
async decodeTrack(track: string): Promise<TrackData>
Decodes a single base64 encoded track.
| Parameter | Type | Description | Optional |
|---|
track | string | The base64 encoded track. | |
| Type | Description |
|---|
Promise<TrackData> | The decoded track. |
async decodeTracks(tracks: string[]): Promise<TrackData[]>
Decodes multiple base64 encoded tracks.
| Parameter | Type | Description | Optional |
|---|
tracks | string[] | An array of base64 encoded tracks. | |
| Type | Description |
|---|
Promise<TrackData[]> | The decoded tracks. |
async destroy(guildId: string): Promise<void>
Destroys a player.
| Parameter | Type | Description | Optional |
|---|
guildId | string | The guild ID. | |
async destroyNode(identifier: string): Promise<void>
Destroys a node. Throws a MagmaStreamError if the node does not exist.
| Parameter | Type | Description | Optional |
|---|
identifier | string | The node identifier. | |
getPlayer(guildId: string): Player | undefined
Returns a player, or undefined if no player exists for the given guild.
| Parameter | Type | Description | Optional |
|---|
guildId | string | The guild ID. | |
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.
async init(options?: ManagerInitOptions): Promise<this>
Initializes the manager, connects all nodes, and loads plugins. Returns immediately if already initiated.
| Type | Description |
|---|
Promise<this> | The manager instance. |
async loadPlayerStates(nodeId: string): Promise<void>
Loads and restores persisted player states for the given node. Supports Memory, JSON, and Redis storage backends.
| Parameter | Type | Description | Optional |
|---|
nodeId | string | The node identifier. | |
on<T extends keyof ManagerEvents>(event: T, listener: (...args: ManagerEvents[T]) => void): this
Attaches an event listener to the manager.
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.
| Parameter | Type | Description | Optional |
|---|
guildId | string | The guild ID. | |
| Type | Description |
|---|
AnyGuild | The resolved guild, or null. |
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.
| Parameter | Type | Description | Optional |
|---|
user | AnyUser | string | The user object or ID. | |
| Type | Description |
|---|
Promise<AnyUser> | The resolved user. |
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.
| Parameter | Type | Description | Optional |
|---|
guildId | string | The 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.
| Parameter | Type | Description | Optional |
|---|
query | string | SearchQuery | The search query or URL. | |
requester | T = unknown | The user who requested the search. | |
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.
sendPacket(packet: GatewayVoiceStateUpdate): unknown
Public proxy for send(). Sends a voice state update packet to the Discord gateway.
async updateVoiceState(data: VoicePacket | VoiceServer | DiscordVoiceState): Promise<void>
Processes an incoming Discord voice packet and updates the relevant player's voice state accordingly.
Returns the most suitable node based on the configured useNode and enablePriorityMode options.
| Type | Description |
|---|
Node | The selected node. |