Player#

A Player is used to interact with a Node via a voice client managed by your Discord library.

class mafic.Player(client, channel, *, node=None)#

Bases: VoiceProtocol, Generic[ClientT]

Represents a player for a guild.

Note

This class is not meant to be instantiated by the user. Use Connectable.connect() from your Discord library to connect.

Parameters:
  • client (ClientT) – The client that the player is associated with.

  • channel (Connectable) – The voice channel to connect to.

  • node (Node[ClientT] | None) – The node to use for the player. If not provided, the best node will be used.

client#

The client that the player is associated with.

Type:

ClientT

channel#

The voice channel that the player is connected to. This is an abc.Connectable from your Discord library.

guild#

The guild that the player is associated with. This is a Guild from your Discord library.

await add_filter(filter, /, *, label, fast_apply=False)#

Add a filter to the player.

Parameters:
  • filter (Filter) – The filter to add.

  • label (str) – The label to use for the filter. This is used to remove the filter later.

  • fast_apply (bool) – Whether to seek to the current position after updating the filters. This clears Lavalink’s internal buffer, which may cause a small delay in the audio.

Raises:

PlayerNotConnected – If the player is not connected to a voice channel.

Return type:

None

cleanup()#

Clean up the player.

This shouldn’t be called directly. Instead, use disconnect().

Return type:

None

await clear_filters(*, fast_apply=False)#

Remove all filters from the player.

Parameters:

fast_apply (bool) – Whether to seek to the current position after updating the filters. This clears Lavalink’s internal buffer, which may cause a small delay in the audio.

Raises:

PlayerNotConnected – If the player is not connected to a voice channel.

Return type:

None

await connect(*, timeout, reconnect, self_mute=False, self_deaf=False)#

Connect to a voice channel.

This is called by your Discord library when using Connectable.connect.

Parameters:
  • timeout (float) – The timeout for the connection.

  • reconnect (bool) – Whether to reconnect to the voice channel if the connection is lost.

  • self_mute (bool) – Whether to mute the bot on connect.

  • self_deaf (bool) – Whether to deafen the bot on connect.

Return type:

None

property connected: bool#

Whether the player is connected to a voice channel.

property current: Track | None#

The current track that is playing.

await disconnect(*, force=False)#

Disconnect from the voice channel.

Parameters:

force (bool) – Whether to force the disconnect even if not connected.

Return type:

None

dispatch_event(data)#

Dispatch an event to the player.

This is called by the library and usually should not be called by the user.

Parameters:

data (EventPayload) – The event payload to dispatch.

Return type:

None

await fetch_tracks(query, search_type=SearchType.YOUTUBE)#

Fetch tracks from the node.

Parameters:
  • query (str) – The query to search for.

  • search_type (SearchType | str) – The search type to use.

Return type:

list[Track] | Playlist | None

Returns:

  • list[Track] – A list of tracks if the load type is TRACK_LOADED or SEARCH_RESULT.

  • Playlist – A playlist if the load type is PLAYLIST_LOADED.

  • None – If the load type is NO_MATCHES.

Notes

If a node was not selected due to not being connected, this will use a random node.

await has_filter(label)#

Check if the player has a filter with the given label.

New in version 2.1.

Parameters:

label (str) – The label to check for.

Returns:

Whether the player has a filter with the given label.

Return type:

bool

is_connected()#

Whether the player is connected to a voice channel.

This is an alias for connected.

Return type:

bool

property node: Node[ClientT]#

The node that the player is connected to.

await pause(pause=True)#

Pause the current track.

Parameters:

pause (bool) – Whether to pause the track.

Raises:

PlayerNotConnected – If the player is not connected to a voice channel.

Return type:

None

Notes

This is a convenience method for update().

property paused: bool#

Whether the player is paused.

property ping: int#

The current ping of the player in milliseconds.

await play(track, /, *, start_time=None, end_time=None, volume=None, replace=True, pause=None)#

Play the given track.

Parameters:
  • track (Track | str) –

    The track to play. This can be a Track or an identifier.

    Changed in version 2.4: The track can now be a str to play an identifier.

  • start_time (Optional[int]) – The position to start the track at.

  • end_time (Optional[int]) – The time to end the track at.

  • volume (Optional[int]) – The volume to play the track at.

  • replace (bool) – Whether to replace the current track if one is playing.

  • pause (Optional[bool]) – Whether to pause the track.

Raises:

PlayerNotConnected – If the player is not connected to a voice channel.

Return type:

None

Notes

This is a convenience method for update().

property position: int#

The current position of the player in milliseconds.

await remove_filter(label, *, fast_apply=False)#

Remove a filter from the player.

Parameters:
  • label (str) – The label of the filter to remove.

  • fast_apply (bool) – Whether to seek to the current position after updating the filters. This clears Lavalink’s internal buffer, which may cause a small delay in the audio.

Raises:
Return type:

None

await resume()#

Resume the current track.

Raises:

PlayerNotConnected – If the player is not connected to a voice channel.

Return type:

None

Notes

This is a convenience method for pause(), with pause set to False.

await seek(position, /)#

Seek to a position in the current track.

Parameters:

position (int) – The position to seek to, in milliseconds.

Raises:

PlayerNotConnected – If the player is not connected to a voice channel.

Return type:

None

Notes

This is a convenience method for update().

await set_volume(volume, /)#

Set the volume of the player.

Parameters:

volume (int) – The volume to set.

Raises:

PlayerNotConnected – If the player is not connected to a voice channel.

Return type:

None

Notes

This is a convenience method for update().

await stop()#

Stop the current track.

Raises:

PlayerNotConnected – If the player is not connected to a voice channel.

Return type:

None

Notes

This is a convenience method for update().

await transfer_to(node)#

Transfer the player to a new node.

Parameters:

node (Node[ClientT]) – The node to transfer to.

Return type:

None

await update(*, track=..., position=None, end_time=None, volume=None, pause=None, filter=None, replace=False)#

Update the player.

Parameters:
  • track (UnionType[Track, str, None]) –

    The track to play. This can be a Track or an identifier.

    Changed in version 2.4: The track can now be a str to play an identifier.

  • position (Optional[int]) – The position to start the track at.

  • end_time (Optional[int]) – The time to end the track at.

  • volume (Optional[int]) – The volume to play the track at.

  • pause (Optional[bool]) – Whether to pause the track.

  • filter (Optional[Filter]) – The filter to apply to the track.

  • replace (bool) – Whether to replace the current track if one is playing.

Raises:

PlayerNotConnected – If the player is not connected to a voice channel.

Return type:

None

class mafic.SearchType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#

Bases: Enum

Represents a search type for Lavalink.

Danger

Many of these require plugins to be used.

LavaSrc:
DuncteBot:
  • SPEECH

APPLE_MUSIC = 'amsearch'#
DEEZER_ISRC = 'dzisrc'#
SOUNDCLOUD = 'scsearch'#
SPOTIFY_RECOMMENDATIONS = 'sprec'#
TTS = 'speak'#
YANDEX_MUSIC = 'ymsearch'#
YOUTUBE = 'ytsearch'#
YOUTUBE_MUSIC = 'ytmsearch'#