Skip to main content
Version: v2.8.4

Class : Player

Constructor

new Magmastream.Player(options: PlayerOptions)
Parameter Type Description Optional
guildIdstring as Guild.idThe guild ID the Player belongs to.
textChannelIdstring as GuildTextChannel.idThe text channel the Player belongs to.
voiceChannelIdstring as GuildVoiceChannel.idThe voice channel the Player belongs to.
nodestring as Node.identifierThe node the Player uses.
volumenumberThe initial volume the Player will use.
selfMutebooleanIf the player should mute itself.
selfDeafenbooleanIf the player should deaf itself.

Table of contents

Properties Methods
autoplayTriesautoMoveNode()
bandsconnect()
dynamicRepeatdeleteSponsorBlock()
filtersdestroy()
guildIddisconnect()
isAutoplayget()
managergetCurrentLyrics()
nodegetRecommendedTracks()
nowPlayingMessagegetSponsorBlock()
pausedmoveNode()
playingpause()
positionplay()
queueprevious()
queueRepeatrestart()
statesearch()
textChannelseek()
trackRepeatset()
voiceChannelsetAutoplay()
voiceStatesetDynamicRepeat()
volumesetNowPlayingMessage()
setQueueRepeat()
setSponsorBlock()
setTextChannelId()
setTrackRepeat()
setVoiceChannelId()
setVolume()
stop()
switchGuild()

Properties

autoplayTries

The number of times to try autoplay before emitting queueEnd.

Return: number | 3 (default value)


bands

The equalizer bands array.

Return: number[]


dynamicRepeat

Whether the queue repeats and shuffles after each song.

Return: boolean


filters

The filters applied to the audio.

Return: Filters


guildId

The guild ID for the player.

Return: string as GuildID


isAutoplay

The autoplay state of the player.

Return: boolean


manager

The Manager for the player.

Return: Manager


node

The Node for the Player.

Return: Node


nowPlayingMessage

The now playing message for the player.

Return: Message


paused

Whether the player is paused.

Return: boolean


playing

Whether the player is playing.

Return: boolean


position

The time the player is in the track.

Return: number


queue

The Queue for the Player.

Return: Queue


queueRepeat

Whether the queue repeats the queue.

Return: boolean


state

The current state of the player.

Return: StateTypes


textChannel

The text channel id for the player.

Return: string as GuildTextChannel.id


trackRepeat

Whether the queue repeats the track.

Return: boolean


voiceChannel

The voice channel id for the player.

Return: string as GuildVoiceChannel.id


voiceState

The voice state object from Discord.

Return: VoiceState


volume

The volume for the player.

Return: number

Methods

autoMoveNode()

async function

Automatically moves the player to a usable node.

Return: Promise<Player | void>


connect()

Connects the player to the voice channel.

Return: this


deleteSponsorBlock()

async function

Deletes the sponsorblock for the player. This will remove all sponsorblock segments that have been set for the player.

Return: Promise<this>


destroy(disconnect)

async function

Destroys the player and clears the queue.

Return: Promise<void>

Parameter Type Description Optional
disconnectbooleanWhether to disconnect the player from the voice channel. If no provided is true

disconnect()

async function

Disconnects the player from the voice channel.

Return: Promise<this>


get(key)

Retrieves custom data associated with a given key.

Return: The data associated with the key, cast to the specified type.

Parameter Type Description Optional
keystringThe key to retrieve the data for.

getCurrentLyrics(skipTrackSource)

async function

Retrieves the current lyrics for the playing track.

This method uses the lavalyrics-plugin to fetch the lyrics. If the plugin is not available, it will throw a RangeError.

Return: Promise<lyrics{}>

Parameter Type Description Optional
skipTrackSourcebooleanIndicates whether to skip the track source when fetching lyrics.

getRecommendedTracks(track, requester)

async function

Gets recommended tracks and returns an array of tracks.

Return: Promise<Track[]>

Parameter Type Description Optional
tracktrack{}The track to find recommendations for.
requesterUser | ClientUserThe user who requested the track.

getSponsorBlock()

async function

Gets the sponsorblock for the player.

Return: Promise<sponsorBlockSegment[]>


moveNode(identifier)

async function

Moves the player to another node.

Return: Promise<sponsorBlockSegment[]>

Parameter Type Description Optional
identifierstring as Node.identifierThe identifier of the node to move to.

pause()

async function

Pauses or resumes the current track.

Return: Promise<this>

Parameter Type Description Optional
pausebooleanA boolean indicating whether to pause (true) or resume (false) the track.

play()

async function

Plays the next track.

If a track is provided, it will be played. Otherwise, the next track in the queue will be played.
If the queue is not empty, but the current track has not finished yet, it will be replaced with the provided track.

Return: Promise<Player>

const { Manager } = require('magmastream');

const manager = new Manager({
...ManagerOptions
})

const searchResponse = await manager.search('Never Gonna Give You Up');

const player = client.lavalink.create({
...PlayerOptions
});

player.connect()
player.queue.add(searchResponse.tracks);

player.play();

previous()

async function

Skips to the previous track in the queue.

Return: Promise<this>


restart()

async function

Restarts the current track to the start.

If there's no current track and there are tracks in the queue, it plays the next track.

Return: Promise<Player>


async function

Same as Manager.search() but a shortcut on the player itself.


seek(position)

async function

Seeks to the specified position in the current track.

Return: Promise<this>

Parameter Type Description Optional
positionnumberThe position in milliseconds to seek to.

set(key, value)

Set custom data.

Return: void

Parameter Type Description Optional
keystringThe key to set the data for.
valueunknownThe value to set the data to.

setAutoplay(autoplayState, botUser, tries)

Sets the autoplay-state of the player.

Autoplay is a feature that makes the player play a recommended track when the current track ends.

Return: this

Parameter Type Description Optional
autoplayStatebooleanWhether or not autoplay should be enabled.
botUserobjectThe user-object that should be used as the bot-user.
triesnumberThe number of times the player should try to find a recommended track if the first one doesn't work.

setDynamicRepeat(repeat, ms)

Sets the queue to repeat and shuffles the queue after each song.

Return: this

Parameter Type Description Optional
repeatbooleanWhether to repeat the queue or not
msnumberAfter how many milliseconds to trigger dynamic repeat.

setNowPlayingMessage(message)

Sets the now playing message.

Return: Message

Parameter Type Description Optional
messageMessageThe message of the now playing message.

setQueueRepeat(repeat)

Sets the queue repeat.

Return: this

Parameter Type Description Optional
repeatbooleanWhether to repeat the queue or not

setSponsorBlock(segments)

async function

Sets the sponsorblock for the player. This will set the sponsorblock segments for the player to the given segments.

Return: Promise<void>

Parameter Type Description Optional
segments SponsorBlockSegmentThe sponsorblock segments to set. Defaults to ["sponsor", "selfpromo"] if not provided.

setTextChannelId(channel)

Sets the player text channel.

This method updates the text channel associated with the player. It also emits a player state update event indicating the change in the channel.

Return: this

Parameter Type Description Optional
channelstring as GuildTextChannel.idThe new text channel ID.

setTrackRepeat(repeat)

Sets the track repeat mode.

When track repeat is enabled, the current track will replay after it ends.
Disables queueRepeat and dynamicRepeat modes if enabled.

Return: this

Parameter Type Description Optional
repeatbooleanWhether to repeat the queue or not

setVoiceChannelId(channel)

Sets the player voice channel.

Return: this

Parameter Type Description Optional
channelstring as GuildVoiceChannel.idThe new voice channel ID.

setVolume(volume)

async function

Sets the player volume.

Return: Promise<this>

Parameter Type Description Optional
volumenumberThe volume to set the player to. Must be between 0 and 100.

stop(amount)

async function

Stops the player and optionally removes tracks from the queue.

Return: Promise<this>

Parameter Type Description Optional
amountnumberThe amount of tracks to remove from the queue. If not provided, removes the current track if it exists.

switchGuild(newOptions, force)

async function

Transfers the player to a new server. If the player already exists on the new server and force is false, this method will return the existing player. Otherwise, a new player will be created and the current player will be destroyed.

Return: Promise<Player>

Parameter Type Description Optional
newOptionsplayerOptions{}The new options for the player.
forcebooleanWhether to force the creation of a new player. Default is false.