pylav.players package#
Subpackages#
- pylav.players.filters package
- Subpackages
- Submodules
- pylav.players.filters.channel_mix module
- pylav.players.filters.distortion module
- pylav.players.filters.equalizer module
- pylav.players.filters.karaoke module
- pylav.players.filters.low_pass module
- pylav.players.filters.misc module
- pylav.players.filters.rotation module
- pylav.players.filters.timescale module
- pylav.players.filters.tremolo module
- pylav.players.filters.vibrato module
- pylav.players.filters.volume module
- Module contents
- pylav.players.query package
- pylav.players.tracks package
Submodules#
pylav.players.manager module#
- class pylav.players.manager.PlayerController(lavalink, player=<class 'pylav.players.player.Player'>)[source]#
Bases:
object
Represents the player manager that contains all the players.
- len(x):
Returns the total amount of cached players.
- iter(x):
Returns an iterator of all the players cached.
- default_player_class#
The player that the player manager is initialized with.
- Type:
BasePlayer
- bot#
The client that the player manager is initialized with.
- Type:
- client#
The client that the player manager is initialized with.
- Type:
Client
- bot#
- client#
- property connected_players#
Returns a list of all the connected players
- async create(channel, endpoint=None, node=None, self_deaf=None, requester=None, feature=None)[source]#
Creates a player if one doesn’t exist with the given information. If node is provided, a player will be created on that node. If endpoint is provided, PyLav will attempt to parse the region from the endpoint and return a node in the parsed region. If node, region and endpoint are left unspecified, or region/endpoint selection fails, PyLav will fall back to the node with the lowest penalty. Region can be omitted if node is specified and vice-versa. :param channel: The voice channel to connect to. :type channel:
discord.channel.VocalGuildChannel
:param endpoint: The address of the Discord voice server. Defaults to None. :type endpoint:str
:param node: The node to put the player on. Defaults to None and a node with the lowest penalty is chosen. :type node:Node
:param requester: The member requesting the player. Defaults to None. :type requester:discord.Member
:param feature: The feature to look for for the initial Node. Defaults to None. :type feature:Optional[:class:`str
]` :param self_deaf: Whether the player should deafen themselves. Defaults to False. :type self_deaf:bool
- Return type:
Player
- default_player_class#
- async destroy(guild_id, requester)[source]#
Removes a player from cache, and also Lavalink if applicable. Ensure you have disconnected the given guild_id from the voicechannel first, if connected. .. warning:
This should only be used if you know what you're doing. Players should never be destroyed unless they have been moved to another :class:`Node`.
- Parameters:
guild_id (
int
) – The guild_id associated with the player to remove.requester (
discord.Member
) – The member requesting the player to be removed.
- property empty_players#
Returns a list of all the empty players
- find_all(predicate=None)[source]#
Returns a list of players that match the given predicate.
- Parameters:
predicate (
Optional[:class:`function
]`) – A predicate to return specific players. Defaults to None.- Return type:
List[:class:`Player
]`
- get(guild_id)[source]#
Gets a player from cache. :param guild_id: The guild_id associated with the player to get. :type guild_id:
int
- Return type:
Optional[:class:`Player
]`
- property global_config#
- property not_playing_players#
Returns a list of all the not playing players
- property paused_players#
Returns a list of all the paused players
- property players#
Returns a dictionary of all players in manager.
- property playing_players#
Returns a list of all the playing players
pylav.players.player module#
- class pylav.players.player.Player(client, channel, *, node=None)[source]#
Bases:
VoiceProtocol
- async add(requester, track, index=None, query=None)[source]#
Adds a track to the queue.
- Parameters:
requester (
int
) – The ID of the user who requested the track.track (
Union[:class:`Track`
,dict
]) – The track to add. Accepts either an Track or a dict representing a track returned from Lavalink.index (
Optional[:class:`int
]`) – The index at which to add the track. If index is left unspecified, the default behaviour is to append the track. Defaults to None.query (
Optional[:class:`Query
]`) – The query that was used to search for the track.
- Return type:
None
- async add_sponsorblock_categories(*categories)[source]#
Add sponsorblock categories to the player. :param categories: The categories to add. :type categories:
str
- async apply_nightcore(requester)[source]#
Applies the NightCore filter to the player. :param requester: Member who requested the filter change :type requester:
discord.Member
- async apply_vaporwave(requester)[source]#
Applies the Vaporwave filter to the player. :param requester: Member who requested the filter change :type requester:
discord.Member
- bot#
- async bulk_add(tracks_and_queries, requester, index=None)[source]#
Adds multiple tracks to the queue. :param tracks_and_queries: A list of tuples containing the track and query. :type tracks_and_queries:
list[Track | dict | str | list[tuple[Track | dict | str
,Query]]]
:param requester: The ID of the user who requested the tracks. :type requester:int
:param index: The index at which to add the tracks. :type index:Optional[:class:`int
]`
- async change_node(node, ops=True, forced=False, skip_position_fetch=False)[source]#
Changes the player’s node :param node: The node the player is changed to. :type node:
Node
:param ops: Whether to change apply the volume and filter ops on change. :type ops:bool
:param forced: Whether to force the change :type forced:bool
:param skip_position_fetch: Whether to skip the position fetch. :type skip_position_fetch:bool
- async change_to_best_node(feature=None, ops=True, forced=True, skip_position_fetch=False)[source]#
Returns the best node to play the current track. :rtype:
Node
- async change_to_best_node_diff_region(feature=None, ops=True, skip_position_fetch=False, forced=False)[source]#
Returns the best node to play the current track in a different region. :rtype:
Node
- property channel#
- channel_id#
- property channel_mix#
The currently applied Channel Mix filter
- client#
- property config#
- async connect(*, timeout=2.0, reconnect=False, self_mute=False, self_deaf=True, requester=None)[source]#
Connects the player to the voice channel. :param timeout: The timeout for the connection. :type timeout:
float
:param reconnect: Whether the player should reconnect if the connection is lost. :type reconnect:bool
:param self_mute: Whether the player should be muted. :type self_mute:bool
:param self_deaf: Whether the player should be deafened. :type self_deaf:bool
:param requester: The member requesting the connection. :type requester:discord.Member
- connected_at#
- property coordinates#
- current#
- delete(key)[source]#
Removes an item from the stored user data. :param key: The key to delete. :type key:
object
- async disconnect(*, force=False, requester, maybe_resuming=False)[source]#
-
An abstract method called when the client terminates the connection.
See
cleanup()
.- Parameters:
force (
bool
) – Whether the disconnection was forced.
- property distortion#
The currently applied Distortion filter
- property echo#
The currently applied Echo filter
- property equalizer#
The currently applied Equalizer filter
- property estimated_position#
Returns the position in the track, adjusted for delta since last update
- fetch(key, default=None)[source]#
Retrieves the related value from the stored user data. :param key: The key to fetch. :type key:
object
:param default: The object that should be returned if the key doesn’t exist. Defaults to None. :type default:Optional[:class:`any
]`- Return type:
any
- property filters#
A list of all filters
- async get_currently_playing_message(embed=True, messageable=None, progress=True, show_help=False)[source]#
- async get_queue_page(page_index, per_page, total_pages, embed=True, messageable=None, history=False)[source]#
- async get_sponsorblock_categories()[source]#
Get the sponsorblock categories for the player. :returns: The categories for the player. :rtype:
list[:class:`str
]`
- property guild#
- property has_effects#
- history#
- property is_active#
Returns the player’s track state
- property is_connected#
Returns whether the player is connected to a voice-channel or not
- property is_empty#
Returns whether the player is empty or not
- property is_playing#
Returns the player’s track state
- property karaoke#
The currently applied Karaoke filter
- last_track#
- property lavalink#
- property low_pass#
The currently applied Low Pass filter
- async move_to(requester, channel, self_mute=False, self_deaf=True)[source]#
Moves the player to a different voice channel. :param channel: The channel to move to. Must be a voice channel. :type channel:
discord.channel.VocalGuildChannel
:param self_mute: Indicates if the player should be self-muted on move. :type self_mute:bool
:param self_deaf: Indicates if the player should be self-deafened on move. :type self_deaf:bool
:param requester: The member requesting to move the player. :type requester:discord.Member
- next_track#
- node#
- async on_voice_server_update(data)[source]#
-
An abstract method that is called when initially connecting to voice. This corresponds to
VOICE_SERVER_UPDATE
.- Parameters:
data (
dict
) – The raw voice server update payload.
- async on_voice_state_update(data)[source]#
-
An abstract method that is called when the client’s voice state has changed. This corresponds to
VOICE_STATE_UPDATE
.- Parameters:
data (
dict
) – The raw voice state payload.
- property paused#
- property ping#
- async play(track, query, requester, start_time=0, end_time=None, no_replace=False, bypass_cache=False, node=None)[source]#
Plays the given track.
- Parameters:
track (
Optional[Union[:class:`Track`
,dict
]]) – The track to play. If left unspecified, this will default to the first track in the queue. Defaults to None so plays the next song in queue. Accepts either an Track or a dict representing a track returned from Lavalink.start_time (
Optional[:class:`int
]`) – Setting that determines the number of milliseconds to offset the track by. If left unspecified, it will start the track at its beginning. Defaults to 0, which is the normal start time.end_time (
Optional[:class:`int
]`) – Settings that determines the number of milliseconds the track will stop playing. By default, track plays until it ends as per encoded data. Defaults to 0, which is the normal end time.no_replace (
Optional[:class:`bool
]`) – If set to true, operation will be ignored if a track is already playing or paused. Defaults to Falsequery (
Optional[:class:`Query
]`) – The query that was used to search for the track.requester (
discord.Member
) – The member that requested the track.bypass_cache (
Optional[:class:`bool
]`) – If set to true, the track will not be looked up in the cache. Defaults to False.node (
Optional[:class:`Node
]`) – The node to use. Defaults the best available node with the needed feature.
- player_manager#
- async position()[source]#
Returns the position in the track, adjusted for delta since last update and the Timescale filter
- position_timestamp#
- property pylav#
- queue#
- property radio#
- ready#
- property region#
- async remove_nightcore(requester)[source]#
Removes the NightCore filter from the player. :param requester: Member who requested the filter change :type requester:
discord.Member
- async remove_vaporwave(requester)[source]#
Removes the Vaporwave filter from the player. :param requester: Member who requested the filter change :type requester:
discord.Member
- property rotation#
The currently applied Rotation filter
- async seek(position, requester, with_filter=False)[source]#
Seeks to a given position in the track. :param position: The new position to seek to in milliseconds. :type position:
int
:param with_filter: Whether to apply the filter or not. :type with_filter:bool
:param requester: The member who requested the seek. :type requester:discord.Member
- async self_deafen(toggle)[source]#
Deafens the player. :param toggle: Indicates if the player should be deafened. :type toggle:
bool
- async set_auto_shuffle(shuffle)[source]#
Sets the player’s auto shuffle state. :param shuffle: Whether to shuffle the player or not. :type shuffle:
bool
- async set_channel_mix(requester, channel_mix, forced=False)[source]#
Sets the ChannelMix of Lavalink. :param channel_mix: ChannelMix to set :type channel_mix:
ChannelMix
:param forced: Whether to force the channel_mix to be set resetting any other filters currently applied :type forced:bool
:param requester: The member who requested the channel_mix :type requester:discord.Member
- async set_distortion(requester, distortion, forced=False)[source]#
Sets the Distortion of Lavalink. :param distortion: Distortion to set :type distortion:
Distortion
:param forced: Whether to force the distortion to be set resetting any other filters currently applied :type forced:bool
:param requester: The member who requested the distortion :type requester:discord.Member
- async set_echo(requester, echo, forced=False)[source]#
Sets the Echo of Lavalink. :param echo: Echo to set :type echo:
Echo
:param forced: Whether to force the low_pass to be set resetting any other filters currently applied :type forced:bool
:param requester: Member who requested the filter change :type requester:discord.Member
- async set_equalizer(requester, equalizer, forced=False)[source]#
Sets the Equalizer of Lavalink. :param equalizer: Equalizer to set :type equalizer:
Equalizer
:param forced: Whether to force the equalizer to be set resetting any other filters currently applied :type forced:bool
:param requester: The member who requested the equalizer to be set :type requester:discord.Member
- async set_filters(*, requester, volume=None, equalizer=None, karaoke=None, timescale=None, tremolo=None, vibrato=None, rotation=None, distortion=None, low_pass=None, channel_mix=None, echo=None, reset_not_set=False)[source]#
Sets the filters of Lavalink. :param volume: Volume to set :type volume:
Volume
:param equalizer: Equalizer to set :type equalizer:Equalizer
:param karaoke: Karaoke to set :type karaoke:Karaoke
:param timescale: Timescale to set :type timescale:Timescale
:param tremolo: Tremolo to set :type tremolo:Tremolo
:param vibrato: Vibrato to set :type vibrato:Vibrato
:param rotation: Rotation to set :type rotation:Rotation
:param distortion: Distortion to set :type distortion:Distortion
:param low_pass: LowPass to set :type low_pass:LowPass
:param channel_mix: ChannelMix to set :type channel_mix:ChannelMix
:param echo: Echo to set :type echo:Echo
:param reset_not_set: Whether to reset any filters that are not set :type reset_not_set:bool
:param requester: Member who requested the filters to be set :type requester:discord.Member
- async set_karaoke(requester, karaoke, forced=False)[source]#
Sets the Karaoke of Lavalink. :param karaoke: Karaoke to set :type karaoke:
Karaoke
:param forced: Whether to force the karaoke to be set resetting any other filters currently applied :type forced:bool
:param requester: The member who requested the karaoke :type requester:discord.Member
- async set_low_pass(requester, low_pass, forced=False)[source]#
Sets the LowPass of Lavalink. :param low_pass: LowPass to set :type low_pass:
LowPass
:param forced: Whether to force the low_pass to be set resetting any other filters currently applied :type forced:bool
:param requester: Member who requested the filter change :type requester:discord.Member
- async set_pause(pause, requester)[source]#
Sets the player’s paused state. :param pause: Whether to pause the player or not. :type pause:
bool
:param requester: The member who requested the pause. :type requester:discord.Member
- async set_repeat(op_type, repeat, requester)[source]#
Sets the player’s repeat state. :param repeat: Whether to repeat the player or not. :type repeat:
bool
:param op_type: The type of repeat to set. Can be either"current"
or"queue"
ordisable
. :type op_type:str
:param requester: The member who requested the repeat change. :type requester:discord.Member
- async set_rotation(requester, rotation, forced=False)[source]#
Sets the Rotation of Lavalink. :param rotation: Rotation to set :type rotation:
Rotation
:param forced: Whether to force the rotation to be set resetting any other filters currently applied :type forced:bool
:param requester: The member who requested the rotation :type requester:discord.Member
- async set_shuffle(shuffle)[source]#
Sets the player’s shuffle state. :param shuffle: Whether to shuffle the player or not. :type shuffle:
bool
- async set_timescale(requester, timescale, forced=False)[source]#
Sets the Timescale of Lavalink. :param timescale: Timescale to set :type timescale:
Timescale
:param forced: Whether to force the timescale to be set resetting any other filters currently applied :type forced:bool
:param requester: The member who requested the timescale :type requester:discord.Member
- async set_tremolo(requester, tremolo, forced=False)[source]#
Sets the Tremolo of Lavalink. :param tremolo: Tremolo to set :type tremolo:
Tremolo
:param forced: Whether to force the tremolo to be set resetting any other filters currently applied :type forced:bool
:param requester: The member who requested the tremolo :type requester:discord.Member
- async set_vibrato(requester, vibrato, forced=False)[source]#
Sets the Vibrato of Lavalink. :param vibrato: Vibrato to set :type vibrato:
Vibrato
:param forced: Whether to force the vibrato to be set resetting any other filters currently applied :type forced:bool
:param requester: The member who requested the vibrato :type requester:discord.Member
- async set_volume(vol, requester)[source]#
Sets the player’s volume .. note:: A limit of 1000 is imposed by Lavalink. (This function also inforces a globally and server set limit.)
- Parameters:
vol (
int
) – The new volume level.requester (
discord.Member
) – The member who requested the volume change.
- async set_volume_filter(requester, volume)[source]#
Sets the volume of Lavalink. :param volume: Volume to set :type volume:
Volume
:param requester: :type requester:discord.Member
- Raises:
ValueError – If the volume is not between 0 and 1000
NodeHasNoFiltersException – If the node does not have specified filter enabled
- stopped#
- store(key, value)[source]#
Stores a value in the player’s memory storage. :param value: The value to store. :type value:
Any
:param key: The key to store the value under. :type key:str
- property timescale#
The currently applied Timescale filter
- property tremolo#
The currently applied Tremolo filter
- property vibrato#
The currently applied Vibrato filter
- property volume#
The current volume.
- property volume_filter#
The currently applied Volume filter
pylav.players.utils module#
- class pylav.players.utils.PlayerQueue(maxsize=0)[source]#
Bases:
Queue
[ANY_GENERIC_TYPE
]A queue, useful for coordinating producer and consumer coroutines.
If maxsize is less than or equal to zero, the queue size is infinite. If it is an integer greater than 0, then “await put()” will block when the queue reaches maxsize, until an item is removed by get().
Unlike the standard library Queue, you can reliably know this Queue’s size with qsize(), since your single-threaded asyncio application won’t be interrupted between calling qsize() and doing an operation on the Queue.
- full()[source]#
Return True if there are maxsize items in the queue.
Note: if the Queue was initialized with maxsize=0 (the default), then full() is never True.
- async get(index=None)[source]#
Remove and return an item from the queue.
If queue is empty, wait until an item is available.
- get_nowait(index=None)[source]#
Remove and return an item from the queue.
Return an item if one is immediately available, else raise QueueEmpty.
- async get_oldest()[source]#
Remove and return an item from the queue.
If queue is empty, wait until an item is available.
- async join()[source]#
Block until all items in the queue have been gotten and processed.
The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer calls task_done() to indicate that the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks.
- property maxsize#
Number of items allowed in the queue
- async put(items, index=None, discard=False)[source]#
Put an item into the queue.
Put an item into the queue. If the queue is full, wait until a free slot is available before adding item.
- put_nowait(items, index=None)[source]#
Put an item into the queue without blocking.
If no free slot is immediately available, raise QueueFull.
- raw_b64s#
- property raw_queue#
- async remove(value, duplicates=False)[source]#
Removes the first occurrence of a value from the queue.
If duplicates is True, all occurrences of the value are removed. Returns the removed entries and number of occurrences removed.
- size()#
Number of items in the queue
- task_done()[source]#
Indicate that a formerly enqueued task is complete.
Used by queue consumers. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete.
If a join() is currently blocking, it will resume when all items have been processed (meaning that a task_done() call was received for every item that had been put() into the queue).
Raises ValueError if called more times than there were items placed in the queue.
- class pylav.players.utils.TrackHistoryQueue(maxsize=0)[source]#
Bases:
PlayerQueue
[ANY_GENERIC_TYPE
],ABC
- get_nowait(index=None)[source]#
Remove and return an item from the queue.
Return an item if one is immediately available, else raise QueueEmpty.
- put_nowait(items, index=None)[source]#
Put an item into the queue without blocking.
If no free slot is immediately available, raise QueueFull.
- raw_b64s#