moonlink.js / Exports / MoonlinkPlayer
Class: MoonlinkPlayer
Table of contents
Constructors
Properties
- autoLeave
- autoPlay
- connected
- current
- data
- guildId
- infos
- loop
- manager
- map
- node
- paused
- ping
- playing
- previous
- queue
- rest
- shuffled
- textChannel
- voiceChannel
- volume
Methods
- connect
- destroy
- disconnect
- get
- pause
- play
- restart
- resume
- seek
- set
- setAutoLeave
- setAutoPlay
- setLoop
- setTextChannel
- setVoiceChannel
- setVolume
- shuffle
- skip
- stop
- updatePlaybackStatus
- updatePlayers
- validateNumberParam
Constructors
constructor
• new MoonlinkPlayer(infos
, manager
, map
): MoonlinkPlayer
Creates an instance of MoonlinkPlayer.
Parameters
Name | Type | Description |
---|---|---|
infos | PlayerInfos | Player information. |
manager | MoonlinkManager | MoonlinkManager instance. |
map | Map <string , any > | Map for storing player data. |
Returns
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
Name | Type | Description |
---|---|---|
options | connectOptions | Connection 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
Name | Type | Description |
---|---|---|
key | string | The 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
Name | Type |
---|---|
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
Name | Type | Description |
---|---|---|
position | number | The 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
Name | Type | Description |
---|---|---|
key | string | The key to set. |
value | unknown | The value to set. |
Returns
void
Defined in
src/@Entities/MoonlinkPlayer.ts:115
setAutoLeave
▸ setAutoLeave(mode?
): boolean
Parameters
Name | Type |
---|---|
mode? | boolean |
Returns
boolean
Defined in
src/@Entities/MoonlinkPlayer.ts:170
setAutoPlay
▸ setAutoPlay(mode
): boolean
Set the auto-play mode for the player.
Parameters
Name | Type | Description |
---|---|---|
mode | boolean | Auto-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
Name | Type | Description |
---|---|---|
mode | string | number | Loop 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
Name | Type | Description |
---|---|---|
channelId | string | The 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
Name | Type | Description |
---|---|---|
channelId | string | The 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
Name | Type | Description |
---|---|---|
percent | number | Volume 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
Name | Type |
---|---|
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
Name | Type |
---|---|
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
Name | Type |
---|---|
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
Name | Type | Description |
---|---|---|
paused | boolean | Indicates 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
Name | Type | Description |
---|---|---|
param | number | The number parameter to validate. |
paramName | string | The name of the parameter. |
Returns
void
Throws
Error if the parameter is not a valid number.