Player#
A Player
is used to interact with a Node
via a voice client managed by
your Discord library.
- asyncadd_filter
- defcleanup
- asyncclear_filters
- asyncconnect
- asyncdisconnect
- defdispatch_event
- asyncfetch_tracks
- asynchas_filter
- defis_connected
- asyncpause
- asyncplay
- asyncremove_filter
- asyncresume
- asyncseek
- asyncset_volume
- asyncstop
- asynctransfer_to
- asyncupdate
- 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.
- 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:
- Raises:
PlayerNotConnected – If the player is not connected to a voice channel.
- Return type:
- cleanup()#
Clean up the player.
This shouldn’t be called directly. Instead, use
disconnect()
.- Return type:
- 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:
- 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
.
- await disconnect(*, force=False)#
Disconnect from the voice channel.
- 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:
- Returns:
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.
- is_connected()#
Whether the player is connected to a voice channel.
This is an alias for
connected
.- Return type:
- 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:
Notes
This is a convenience method for
update()
.
- await play(track, /, *, start_time=None, end_time=None, volume=None, replace=True, pause=None)#
Play the given track.
- Parameters:
- Raises:
PlayerNotConnected – If the player is not connected to a voice channel.
- Return type:
Notes
This is a convenience method for
update()
.
- await remove_filter(label, *, fast_apply=False)#
Remove a filter from the player.
- Parameters:
- Raises:
PlayerNotConnected – If the player is not connected to a voice channel.
ValueError – If the filter does not exist.
- Return type:
- await resume()#
Resume the current track.
- Raises:
PlayerNotConnected – If the player is not connected to a voice channel.
- Return type:
Notes
This is a convenience method for
pause()
, withpause
set toFalse
.
- 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:
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:
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:
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.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:
- class mafic.SearchType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#
Bases:
Enum
Represents a search type for Lavalink.
- APPLE_MUSIC = 'amsearch'#
- DEEZER_ISRC = 'dzisrc'#
- DEEZER_SEARCH = 'dzsearch'#
- SOUNDCLOUD = 'scsearch'#
- SPOTIFY_RECOMMENDATIONS = 'sprec'#
- SPOTIFY_SEARCH = 'spsearch'#
- TTS = 'speak'#
- YANDEX_MUSIC = 'ymsearch'#
- YOUTUBE = 'ytsearch'#
- YOUTUBE_MUSIC = 'ytmsearch'#