Player
Class representing a Hoshimi player.
Signature
export declare class PlayerPrivate types
NonGuildUpdatePlayerInfoTypeAlias
type NonGuildUpdatePlayerInfo = Omit<UpdatePlayerInfo, "guildId">;JSDoc
Properties
25Methods
17Properties
private destroyPromise;Promise of the destroying player.
readonly data: PlayerStorageAdapter;The data for the player.
readonly options: PlayerOptions;The options for the player.
readonly manager: Hoshimi;The manager for the player.
readonly queue: QueueStructure;The queue for the player.
readonly filterManager: FilterManager;The filter manager for the player.
node: NodeStructure;The node for the player.
selfDeaf: boolean;Check if the player is self deafened.
selfMute: boolean;Check if the player is self muted.
loop: LoopMode;Loop mode of the player.
playing: boolean;Check if the player is playing.
paused: boolean;Check if the player is paused.
connected: boolean;Check if the player is connected.
destroyedGetterget destroyed(): boolean;Check if the player is destroyed.
volume: number;Volume of the player.
guildId: string;Guild id of the player.
voiceId: string | undefined;Voice channel id of the player.
textId: string | undefined;Text channel id of the player.
ping: number;The ping of the player.
createdTimestamp: number;The timestamp when the player was created.
lastPosition: number;The last position received from Lavalink.
lastPositionUpdate: number | null;The timestamp when the last position change update happened.
positionGetterget position(): number;The current calculated position of the player.
readonly voice: PlayerVoiceStateStructure;The voice connection details.
readonly lyrics: LyricsMethods;The lyrics methods for the player.
Methods
constructorConstructorconstructor(manager: Hoshimi, options: PlayerOptions);isPlaying(): boolean;Check if the player is currently playing a track.
Returns
Whether the player is currently playing a track.
search(options: SearchOptions): Promise<QueryResult>;Search for a track or playlist.
Parameters
options- The options for the search.
Returns
The search result.
Examples
const player = manager.getPlayer("guildId");
const result = await player.search({
query: "track name",
source: SearchSource.Youtube,
requester: {},
});
console.log(result) // the search resultconnect(): 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,
});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 trackseek(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 secondsmove(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");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);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 datatoJSON(): 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