Reference#
Pool#
- class discord.ext.lava.Pool#
- nodes: dict[str, discord.ext.lava.node.Node[Bot, Player]] = {}#
A mapping of node identifiers to nodes that are attached to this pool.
- classmethod await create_node(*, bot: Bot, provider: Provider, identifier: str, host: Optional[str] = None, port: Optional[str] = None, ws_url: Optional[str] = None, ws_path: Optional[str] = None, rest_url: Optional[str] = None, password: Optional[str] = None, json_dumps: Optional[Callable[[...], str]] = None, json_loads: Optional[Callable[[...], dict[str, Any]]] = None, spotify_client_id: Optional[str] = None, spotify_client_secret: Optional[str] = None, session: Optional[ClientSession] = None) Node[Bot, Player]#
Creates a new node, connects it to its provider server, and adds it to the pool.
Note
You must set either the host and port or ws_url and rest_url parameters.
- Parameters:
bot – The bot instance that this node should be attached to.
provider – An enum representing which external application this node will use, such as obsidian or lavalink.
identifier – A unique identifier for this node.
host – The host that this node will use for WebSocket connections and HTTP requests. If you want to construct a
ws_urlandrest_urlyourself, you can passNonefor this parameter.port – The port that this node will use for WebSocket connections and HTTP requests. If you want to construct a
ws_urlandrest_urlyourself, you can passNonefor this parameter.ws_url – The url that will be used to connect to the websocket. Constructing this url manually is optional and will override the
hostandportparameters.ws_path – The path that will be used to connect to the websocket. Optional, if
None, the default path for the selectedproviderwill be used.rest_url – The url that will be used to make HTTP requests. Constructing this url manually is optional and will override the
hostandportparameters.password – The password to use for connections with the provider server. Optional, if the provider does not require a password you can omit this parameter or pass
None.json_dumps – The callable that will be used to serialize JSON data. Optional, if
None, the built-injson.dumpswill be used.json_loads – The callable that will be used to deserialize JSON data. Optional, if
None, the built-injson.loadswill be used.spotify_client_id – The spotify client ID to use with the builtin spotify integration. Optional, if
None, spotify support will be disabled.spotify_client_secret – The spotify client secret to use with the builtin spotify integration. Optional, if
None, spotify support will be disabled.session – The aiohttp session to use for WebSocket connections and HTTP requests. Optional, if
None, a new session will be created.
- Raises:
ValueError – If you don’t provide either
hostandportorws_urlandrest_url.NodeAlreadyExists – If a node with the given identifier already exists.
InvalidNodePassword – If the password provided did not match the password required by the provider server.
NodeConnectionError – If the node could not connect to the provider server.
- Return type:
- classmethod get_node(identifier: Optional[str] = None) Node[Bot, Player]#
Retrieves the node with the given identifier from the pool, or a random one if an identifier is not provided.
- Parameters:
identifier – The identifier of the node to return. Optional, if
None, a random node will be returned.- Raises:
NoNodesConnected – If there are no nodes attached to the pool.
NodeNotFound – If there are no nodes with the given identifier in the pool.
- Return type:
- classmethod await remove_node(identifier: str) None#
Removes the node with the given identifier from the pool. This also calls the nodes
Node.disconnect()method which in turn calls each player’sPlayer.disconnect()method.- Parameters:
identifier – The identifier of the node to remove.
Node#
- class discord.ext.lava.Node(*, bot: Bot, provider: Provider, identifier: str, host: Optional[str] = None, port: Optional[str] = None, ws_url: Optional[str] = None, ws_path: Optional[str] = None, rest_url: Optional[str] = None, password: Optional[str] = None, json_dumps: Optional[Callable[[...], str]] = None, json_loads: Optional[Callable[[...], dict[str, Any]]] = None, spotify_client_id: Optional[str] = None, spotify_client_secret: Optional[str] = None, session: Optional[ClientSession] = None)#
A Node handles the interactions between your bot and a provider server such as obsidian or lavalink. These interactions include connecting to the websocket, searching for tracks, and managing player state.
See
Pool.create_node()for more information about creating a node.- property provider: Provider#
An enum representing which external application this node is using, such as obsidian or lavalink.
- property players: dict[int, Player]#
A mapping of guild id to player instance that this node is managing.
- await search(search: str, /, *, source: Source = Source.NONE, **extras: Any) Search#
Requests search results from this node’s provider server, or other services like spotify.
- Parameters:
search (
str) – The search query.source (
Source) – The source to request results from. Defaults toSource.NONE.
- Raises:
NoResultsFound – If no results were found.
SearchFailed – If the search failed.
HTTPError – If the HTTP request failed.
- Return type:
Player#
- class discord.ext.lava.Player(client: ~discord.ext.commands.Bot = <MISSING>, channel: ~discord.VoiceChannel | ~discord.StageChannel = <MISSING>, /, *, node: ~typing.Optional[~discord.ext.lava.node.Node[~discord.ext.commands.Bot, ~discord.ext.lava.Player]] = None)#
-
- property voice_channel: VoiceChannel | StageChannel#
The voice channel that this player is connected to.
- property current_track_id: str | None#
The ID of the current track. This is
Noneif no track is playing.
- property current: discord.ext.lava.objects.track.Track | None#
The current track. This is
Noneif no track is playing.
- property filter: discord.ext.lava.objects.filters.filter.Filter | None#
The players current filter. This is
Noneif no filter has been set yet.
- property listeners: list[discord.member.Member]#
Returns a list of non bot members in the players voice channel who are also not deafened.
- is_connected() bool#
Whether the player is connected to a voice channel.
Trueif connected,Falseif not.
- await connect(*, timeout: Optional[float] = None, reconnect: Optional[bool] = None, self_mute: bool = False, self_deaf: bool = True) None#
Connects the player to its voice channel.
- Parameters:
timeout – Unused parameter, does nothing.
reconnect – Unused parameter, does nothing.
self_mute –
Trueif the player should be muted when connected. Defaults toFalse.self_deaf –
Trueif the player should be deafened when connected. Defaults toTrue.
- await disconnect(*, force: bool = False) None#
Disconnects the player from its voice channel and removes it from the node.
- Parameters:
force –
Trueif the player should send a request to the provider server to stop the current track even if one is not playing. Defaults toFalse.
- await play(track: Track, /, *, start_time: Optional[int] = None, end_time: Optional[int] = None, no_replace: bool = False) None#
Plays the given track.
- Parameters:
track – The track to play.
start_time – The start time of the track in milliseconds. Defaults to
None.end_time – The end time of the track in milliseconds. Defaults to
None.no_replace –
Trueif this track should not replace the current track, if any. Defaults toFalse.
- await stop(*, force: bool = False) None#
Stops the current track.
- Parameters:
force –
Trueif the player should send the stop track request to the provider server even if this player’scurrentattribute isNone. Defaults toFalse.
- await set_pause(pause: bool, /) None#
Sets the players pause state.
- Parameters:
pause –
Trueif the player should be paused,Falseotherwise.
- await set_filter(filter: Filter, /, *, set_position: bool = True) None#
Sets the players filter.
- Parameters:
filter – The filter to set.
set_position –
Trueif the player should set its position to the current position which applies filters instantly. Defaults toTrue.
- await set_position(position: float, /, *, force: bool = False) None#
Sets the players position.
- Parameters:
position – The position to set, in milliseconds.
force –
Trueif the player should send the set position request to the provider server even if this player’scurrentattribute isNone. Defaults toFalse.
Queue#
- class discord.ext.lava.Queue#
- property loop_mode: QueueLoopMode#
Returns the current queue loop mode.
- set_loop_mode(mode: QueueLoopMode, /) None#
Sets the queue loop mode.
- Parameters:
mode – The loop mode to set.
- get_from_front(*, put_into_history: bool = True) Track#
Removes and returns the first item in the queue.
This method also:
Adds the item to the queue history if
put_into_historyisTrue.Puts the item back into the queue at the front if
Queue.loop_modeisQueueLoopMode.CURRENT.Puts the item back into the queue at the end if
Queue.loop_modeisQueueLoopMode.ALL.
- Parameters:
put_into_history – Whether the item should be added to the queue history. Optional, defaults to
True.- Raises:
IndexError – If the queue is empty.
- Return type:
- get_from_position(position: int, /, *, put_into_history: bool = True) Track#
Removes and returns an item at the given position from the queue.
The note from
Queue.get_from_front()also applies here.- Parameters:
position – The position of the item to remove and return.
put_into_history – Whether the item should be added to the queue history. Optional, defaults to
True.
- Raises:
IndexError – If there is no item at the given position.
- Return type:
- await wait_for_item(*, put_into_history: bool = True) Track#
Waits until an item has been added to the queue and returns it.
- Parameters:
put_into_history – Whether the item should be added to the queue history. Optional, defaults to
True.
- put_at_front(*, item: QueueItemT | None = None, items: list[QueueItemT] | None = None) None#
Puts an item, or items, into the front of the queue.
- Parameters:
item – The item to put into the queue.
items – The items to put into the queue.
Warning
Only one of
itemanditemscan be specified.- Raises:
ValueError – If both or none of
itemanditemsare specified.
- put_at_position(position: int, /, *, item: QueueItemT | None = None, items: list[QueueItemT] | None = None) None#
Puts an item, or items, into the queue at the given position.
- Parameters:
position – The position to insert the item or items at.
item – The item to put into the queue.
items – The items to put into the queue.
Warning
Only one of
itemanditemscan be specified.- Raises:
ValueError – If both or none of
itemanditemsare specified.
- put_at_end(*, item: QueueItemT | None = None, items: list[QueueItemT] | None = None) None#
Puts an item (or items) at the end of the queue.
- Parameters:
item – The item to put into the queue.
items – The items to put into the queue.
Warning
Only one of
itemanditemscan be specified.- Raises:
ValueError – If both or none of
itemanditemsare specified.
- get_from_history(*, position: int) Track#
Get the item at the given position from the queue history.
- Parameters:
position – The position of the item to get from the queue history.
- Raises:
IndexError – If there is no item at the given position.
- Return type:
- pop_from_history(*, position: int) Track#
Removes and returns the item at the given position from the queue history.
- Parameters:
position – The position of the item to remove and return from the queue history.
- Raises:
IndexError – If there is no item at the given position.
- Return type:
- put_into_history(*, position: int | None = None, item: QueueItemT | None = None, items: list[QueueItemT] | None = None) None#
Puts an item, or items, into the queue history at the given position.
- Parameters:
position – The position to insert the item or items at. Optional, defaults to
Nonewhich adds the item(s) to the end of the history. (which means they will be fetched first byQueue.get_from_history())item – The item to put into the queue history.
items – The items to put into the queue history.
Warning
Only one of
itemanditemscan be specified.- Raises:
ValueError – If both or none of
itemanditemsare specified.
Objects#
Track#
Collection#
Search#
- class discord.ext.lava.Search(*, source: Source, type: str, result: spotipy.objects.album.Album | spotipy.objects.playlist.Playlist | spotipy.objects.artist.Artist | spotipy.objects.track.Track | list[discord.ext.lava.objects.track.Track] | discord.ext.lava.objects.collection.Collection, tracks: list[discord.ext.lava.objects.track.Track])#
-
- property result: spotipy.objects.album.Album | spotipy.objects.playlist.Playlist | spotipy.objects.artist.Artist | spotipy.objects.track.Track | list[discord.ext.lava.objects.track.Track] | discord.ext.lava.objects.collection.Collection#
- property tracks: list[discord.ext.lava.objects.track.Track]#
Events#
TrackStart#
TrackEnd#
TrackStuck#
TrackException#
WebsocketOpen#
WebsocketClosed#
Filters#
ChannelMix#
- class discord.ext.lava.ChannelMix(*, left_to_left: float = 1.0, left_to_right: float = 0.0, right_to_left: float = 0.0, right_to_right: float = 1.0)#
-
- classmethod mono() ChannelMix#
- classmethod only_left() ChannelMix#
- classmethod full_left() ChannelMix#
- classmethod only_right() ChannelMix#
- classmethod full_right() ChannelMix#
- classmethod switch() ChannelMix#
Distortion#
Equalizer#
Karaoke#
LowPass#
Rotation#
Timescale#
Tremolo#
Vibrato#
Volume#
Filter#
- class discord.ext.lava.Filter(filter: Optional[Filter] = None, channel_mix: Optional[ChannelMix] = None, distortion: Optional[Distortion] = None, equalizer: Optional[Equalizer] = None, karaoke: Optional[Karaoke] = None, low_pass: Optional[LowPass] = None, rotation: Optional[Rotation] = None, timescale: Optional[Timescale] = None, tremolo: Optional[Tremolo] = None, vibrato: Optional[Vibrato] = None, volume: Optional[Volume] = None)#
-
- channel_mix: discord.ext.lava.objects.filters.channel_mix.ChannelMix | None#
- distortion: discord.ext.lava.objects.filters.distortion.Distortion | None#
Enums#
Provider#
QueueLoopMode#
Source#
- class discord.ext.lava.Source(value)#
An enumeration.
- BANDCAMP = 'bandcamp'#
- YARN = 'getyarn.io'#
- HTTP = 'http'#
- LOCAL = 'local'#
- NICO = 'niconico'#
- SOUNDCLOUD = 'soundcloud'#
- TWITCH = 'twitch'#
- VIMEO = 'vimeo'#
- YOUTUBE = 'youtube'#
- YOUTUBE_MUSIC = 'youtube_music'#
- SPOTIFY = 'spotify'#
- UNKNOWN = 'unknown'#
- NONE = ''#
Exceptions#
LavaError#
- exception discord.ext.lava.LavaError#
NodeAlreadyExists#
- exception discord.ext.lava.NodeAlreadyExists#
NodeNotFound#
- exception discord.ext.lava.NodeNotFound#
NoNodesConnected#
- exception discord.ext.lava.NoNodesConnected#
NodeAlreadyConnected#
- exception discord.ext.lava.NodeAlreadyConnected#
NodeConnectionError#
- exception discord.ext.lava.NodeConnectionError#
InvalidPassword#
- exception discord.ext.lava.InvalidPassword#
NodeNotConnected#
- exception discord.ext.lava.NodeNotConnected#
HTTPError#
NoResultsFound#
SearchFailed#
Utils#
SPOTIFY_URL_REGEX#
- discord.ext.lava.SPOTIFY_URL_REGEX#
A regex that matches spotify URLs for tracks, albums, playlists, and artists.
MISSING#
- discord.ext.lava.MISSING#
A sentinel value that is used to indicate a missing value with distinction from None.