moonlink.js / Exports / MoonlinkPlayer

Class: MoonlinkPlayer

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new MoonlinkPlayer(infos, manager, map): MoonlinkPlayer

Creates an instance of MoonlinkPlayer.

Parameters

NameTypeDescription
infosPlayerInfosPlayer information.
managerMoonlinkManagerMoonlinkManager instance.
mapMap<string, any>Map for storing player data.

Returns

MoonlinkPlayer

Defined in

src/@Entities/MoonlinkPlayer.ts:39

Properties

autoLeave

autoLeave: boolean

Defined in

src/@Entities/MoonlinkPlayer.ts:18


autoPlay

autoPlay: boolean

Defined in

src/@Entities/MoonlinkPlayer.ts:17


connected

connected: boolean

Defined in

src/@Entities/MoonlinkPlayer.ts:19


current

current: Record<string, any>

Defined in

src/@Entities/MoonlinkPlayer.ts:27


data

data: Record<string, any>

Defined in

src/@Entities/MoonlinkPlayer.ts:29


guildId

guildId: string

Defined in

src/@Entities/MoonlinkPlayer.ts:14


infos

Private infos: PlayerInfos

Defined in

src/@Entities/MoonlinkPlayer.ts:12


loop

loop: number

Defined in

src/@Entities/MoonlinkPlayer.ts:22


manager

manager: MoonlinkManager

Defined in

src/@Entities/MoonlinkPlayer.ts:11


map

Private map: Map<string, any>

Defined in

src/@Entities/MoonlinkPlayer.ts:13


node

node: any

Defined in

src/@Entities/MoonlinkPlayer.ts:30


paused

paused: boolean

Defined in

src/@Entities/MoonlinkPlayer.ts:21


ping

ping: number

Defined in

src/@Entities/MoonlinkPlayer.ts:25


playing

playing: boolean

Defined in

src/@Entities/MoonlinkPlayer.ts:20


previous

previous: Record<string, any>

Defined in

src/@Entities/MoonlinkPlayer.ts:28


queue

queue: MoonlinkQueue

Defined in

src/@Entities/MoonlinkPlayer.ts:26


rest

rest: MoonlinkRestFul

Defined in

src/@Entities/MoonlinkPlayer.ts:31


shuffled

shuffled: boolean

Defined in

src/@Entities/MoonlinkPlayer.ts:24


textChannel

textChannel: string

Defined in

src/@Entities/MoonlinkPlayer.ts:15


voiceChannel

voiceChannel: string

Defined in

src/@Entities/MoonlinkPlayer.ts:16


volume

volume: number

Defined in

src/@Entities/MoonlinkPlayer.ts:23

Methods

connect

connect(options): boolean

Connect the player to a voice channel with optional connection options.

Parameters

NameTypeDescription
optionsconnectOptionsConnection options (setMute, setDeaf).

Returns

boolean

True if the connection was successful.

Defined in

src/@Entities/MoonlinkPlayer.ts:203


destroy

destroy(): Promise<boolean>

Destroy the player, disconnecting it and removing player data.

Returns

Promise<boolean>

True if the player was successfully destroyed.

Defined in

src/@Entities/MoonlinkPlayer.ts:487


disconnect

disconnect(): boolean

Disconnect the player from the voice channel.

Returns

boolean

True if the disconnection was successful.

Defined in

src/@Entities/MoonlinkPlayer.ts:226


get

get<T>(key): T

Get a value from the player's data.

Type parameters

Name
T

Parameters

NameTypeDescription
keystringThe key to retrieve.

Returns

T

The value associated with the key.

Defined in

src/@Entities/MoonlinkPlayer.ts:125


pause

pause(): Promise<boolean>

Pause the playback.

Returns

Promise<boolean>

True if paused successfully.

Defined in

src/@Entities/MoonlinkPlayer.ts:330


play

play(track?): Promise<boolean>

Play the next track in the queue.

Parameters

NameType
track?string | MoonlinkTrack

Returns

Promise<boolean>

Defined in

src/@Entities/MoonlinkPlayer.ts:276


restart

restart(): Promise<void>

Restart the player by reconnecting and updating its state.

Returns

Promise<void>

Defined in

src/@Entities/MoonlinkPlayer.ts:247


resume

resume(): Promise<boolean>

Resume the playback.

Returns

Promise<boolean>

True if resumed successfully.

Defined in

src/@Entities/MoonlinkPlayer.ts:340


seek

seek(position): Promise<number>

Seek to a specific position in the current track.

Parameters

NameTypeDescription
positionnumberThe position to seek to.

Returns

Promise<number>

The new position after seeking.

Throws

Error if the position is greater than the track duration or seek is not allowed.

Defined in

src/@Entities/MoonlinkPlayer.ts:522


set

set(key, value): void

Set a key-value pair in the player's data and update the map.

Parameters

NameTypeDescription
keystringThe key to set.
valueunknownThe value to set.

Returns

void

Defined in

src/@Entities/MoonlinkPlayer.ts:115


setAutoLeave

setAutoLeave(mode?): boolean

Parameters

NameType
mode?boolean

Returns

boolean

Defined in

src/@Entities/MoonlinkPlayer.ts:170


setAutoPlay

setAutoPlay(mode): boolean

Set the auto-play mode for the player.

Parameters

NameTypeDescription
modebooleanAuto-play mode (true/false).

Returns

boolean

True if the mode was set successfully.

Throws

Error if mode is not a boolean.

Defined in

src/@Entities/MoonlinkPlayer.ts:187


setLoop

setLoop(mode): string | number

Set the loop mode for the player.

Parameters

NameTypeDescription
modestring | numberLoop mode (0 for no loop, 1 for single track, 2 for entire queue).

Returns

string | number

The new loop mode.

Throws

Error if the mode is not a valid number or out of range.

Defined in

src/@Entities/MoonlinkPlayer.ts:459


setTextChannel

setTextChannel(channelId): boolean

Set the text channel for the player.

Parameters

NameTypeDescription
channelIdstringThe ID of the text channel.

Returns

boolean

True if the channel was set successfully.

Throws

Error if channelId is empty or not a string.

Defined in

src/@Entities/MoonlinkPlayer.ts:136


setVoiceChannel

setVoiceChannel(channelId): boolean

Set the voice channel for the player.

Parameters

NameTypeDescription
channelIdstringThe ID of the voice channel.

Returns

boolean

True if the channel was set successfully.

Throws

Error if channelId is empty or not a string.

Defined in

src/@Entities/MoonlinkPlayer.ts:156


setVolume

setVolume(percent): Promise<number>

Set the volume level for the player.

Parameters

NameTypeDescription
percentnumberVolume percentage (0 to Infinity).

Returns

Promise<number>

The new volume level.

Throws

Error if the volume is not a valid number or player is not playing.

Defined in

src/@Entities/MoonlinkPlayer.ts:433


shuffle

shuffle(mode?): boolean

Shuffle the tracks in the queue.

Parameters

NameType
mode?boolean

Returns

boolean

True if the shuffle was successful.

Throws

Error if the queue is empty.

Defined in

src/@Entities/MoonlinkPlayer.ts:550


skip

skip(position?): Promise<boolean>

Skip to the next track in the queue.

Parameters

NameType
position?number

Returns

Promise<boolean>

True if the next track was successfully played.

Defined in

src/@Entities/MoonlinkPlayer.ts:382


stop

stop(destroy?): Promise<boolean>

Stop the playback and optionally clear player data.

Parameters

NameType
destroy?boolean

Returns

Promise<boolean>

True if stopped successfully.

Defined in

src/@Entities/MoonlinkPlayer.ts:363


updatePlaybackStatus

updatePlaybackStatus(paused): Promise<void>

Private method to update the playback status (paused or resumed).

Parameters

NameTypeDescription
pausedbooleanIndicates whether to pause or resume the playback.

Returns

Promise<void>

Defined in

src/@Entities/MoonlinkPlayer.ts:350


updatePlayers

updatePlayers(): void

Private method to update player information in the map.

Returns

void

Defined in

src/@Entities/MoonlinkPlayer.ts:104


validateNumberParam

validateNumberParam(param, paramName): void

Private method to validate a number parameter.

Parameters

NameTypeDescription
paramnumberThe number parameter to validate.
paramNamestringThe name of the parameter.

Returns

void

Throws

Error if the parameter is not a valid number.

Defined in

src/@Entities/MoonlinkPlayer.ts:508