Classes

Player

Class representing a Hoshimi player.

Signature

export declare class Player

Private types

NonGuildUpdatePlayerInfoTypeAlias

JSDoc

@classPlayer

Properties

private destroyPromise;

Promise of the destroying player.

@type{PromiseWithResolvers<void>["promise"] | null}
readonly manager: Hoshimi;

The manager for the player.

@type{Hoshimi}@readonly
selfDeaf: boolean;

Check if the player is self deafened.

@type{boolean}
selfMute: boolean;

Check if the player is self muted.

@type{boolean}
loop: LoopMode;

Loop mode of the player.

@type{LoopMode}@defaultLoopMode.Off
playing: boolean;

Check if the player is playing.

@type{boolean}@defaultfalse
paused: boolean;

Check if the player is paused.

@type{boolean}@defaultfalse
connected: boolean;

Check if the player is connected.

@type{boolean}@defaultfalse
get destroyed(): boolean;

Check if the player is destroyed.

@type{boolean}
volume: number;

Volume of the player.

@type{number}@default100
guildId: string;

Guild id of the player.

@type{string}
voiceId: string | undefined;

Voice channel id of the player.

@type{string | undefined}
textId: string | undefined;

Text channel id of the player.

@type{string | undefined}
ping: number;

The ping of the player.

@type{number}
createdTimestamp: number;

The timestamp when the player was created.

@type{number}
lastPosition: number;

The last position received from Lavalink.

@type{number}
lastPositionUpdate: number | null;

The timestamp when the last position change update happened.

@type{number | null}
positionGetter
get position(): number;

The current calculated position of the player.

@type{number}@readonly
readonly lyrics: LyricsMethods;

The lyrics methods for the player.

@type{LyricsMethods}@readonly

Methods

isPlaying(): boolean;

Check if the player is currently playing a track.

Returns

Whether the player is currently playing a track.

connect(): Promise<this>;

Connect the player to the voice channel.

Returns

The player instance.

Examples

const player = manager.getPlayer("guildId");
player.connect();
disconnect(): Promise<this>;

Disconnect the player from the voice channel.

Returns

The player instance.

Examples

const player = manager.getPlayer("guildId");
player.disconnect();
play(options?: Partial<PlayOptions>): Promise<void>;

Play a track in the player.

Parameters

options
The options to play the track.

Returns

Examples

const player = manager.getPlayer("guildId");

player.play({
	track: track,
	noReplace: true,
});
@throws{PlayerError} If there are no tracks to play.
stop(options?: Partial<StopOptions>): Promise<void>;

Stop the player from playing.

Parameters

options
The options for stopping the player.

Returns

Examples

// Stop and destroy the player (default)
const player = manager.getPlayer("guildId");
await player.stop();

// Stop without destroying, only clear queue
await player.stop({ destroy: false, clearQueue: true });

// Stop and leave voice channel
await player.stop({ destroy: false, leaveVoice: true });
skip(options?: SkipOptions): Promise<void>;

Play the next track in the queue.

Parameters

options
The options for skipping tracks.

Returns

Examples

const player = manager.getPlayer("guildId");
player.skip({ to: 2 }); // skip 2 tracks
player.skip(); // skip 1 track
@throws{PlayerError} If there are no tracks to skip.
seek(position: number): Promise<void>;

Seek to a specific position in the current track.

Parameters

position
The position to seek to in milliseconds.

Returns

Examples

const player = manager.getPlayer("guildId");
player.seek(30000); // seek to 30 seconds
@throws{PlayerError} If the position is invalid.
move(node: NodeIdentifier): Promise<void>;

Change the node the player is connected to.

Parameters

node
The node to change to.

Returns

A promise that resolves when the node has been changed.

Examples

const player = manager.getPlayer("guildId");
player.move("newNodeId");
@throws{PlayerError} If the target node is not found, not connected, or missing source managers.
destroy(options?: DestroyOptions): Promise<void>;

Destroy and disconnect the player.

Parameters

options
The options for destroying the player.

Returns

Examples

const player = manager.getPlayer("guildId");
player.destroy({ reason: DestroyReasons.Stop });
setPaused(paused?: boolean): Promise<boolean>;

Pause or resume the player.

Parameters

paused
Whether to pause; defaults to toggling the current state.

Returns

The resulting paused state.

Examples

const player = manager.getPlayer("guildId");
player.setPaused();
setVolume(volume: number): Promise<void>;

Set the volume of the player.

Parameters

volume
The volume to set.

Returns

Examples

const player = manager.getPlayer("guildId");
player.setVolume(50); // set the volume to 50%
setLoop(mode: LoopMode): this;

Set the loop mode of the player.

Parameters

mode
The loop mode to set.

Returns

The player instance.

Examples

const player = manager.getPlayer("guildId");
player.setLoop(LoopMode.Track);
@throws{PlayerError} If the loop mode is invalid.
setVoice(options?: NullableVoiceChannelUpdate): Promise<void>;

Set the voice of the player.

Parameters

options
The voice state to set.

Returns

Examples

const player = manager.getPlayer("guildId");
player.setVoice({ voiceId: "newVoiceId" });
updatePlayer(data: NonGuildUpdatePlayerInfo): Promise<LavalinkPlayer | null>;

Update the player with new data.

Parameters

data
The data to update the player with.

Returns

The updated player data.

Examples

const player = manager.getPlayer("guildId");
const updatedPlayer = await player.updatePlayer({ volume: 50 });
console.log(updatedPlayer); // the updated player data
toJSON(): PlayerJSON;

Return the player as a json object.

Returns

Examples

const player = manager.getPlayer("guildId");
const json = player.toJSON();
console.log(json); // the player as a json object