API Reference#

Pool#

class slate.Pool#
nodes: dict[str, slate.node.Node[BotT, PlayerT]] = {}#
classmethod await create_node(*, bot: BotT, session: Optional[ClientSession] = None, provider: Provider, identifier: str, host: str, port: str, password: str, secure: bool = False, resume_key: Optional[str] = None, rest_url: Optional[str] = None, ws_url: 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) Node[BotT, PlayerT]#
classmethod get_node(identifier: Optional[str] = None) Node[BotT, PlayerT]#
classmethod await remove_node(identifier: str, *, force: bool = False) None#

Node#

class slate.Node#

Node’s handle interactions between your bot and a provider server such as obsidian or lavalink. This includes connecting to the websocket, searching for tracks, and managing player state.

__init__(*, bot: BotT, session: Optional[ClientSession] = None, provider: Provider, identifier: str, host: str, port: str, password: str, secure: bool = False, resume_key: Optional[str] = None, rest_url: Optional[str] = None, ws_url: 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) None#
Parameters
  • bot – The bot instance that this node belongs to.

  • session – The aiohttp client session to use for websocket/rest communication. Optional, if None (default), a new one will be created.

  • provider – An enum denoting which external application this node is connecting to, such as slate.Provider.OBSIDIAN.

  • identifier – A unique identifier for this node.

  • host – The hostname of the provider server.

  • port – The port of the provider server.

  • password – The password for the provider server.

  • secure – Whether to use secure connections for websocket/rest communication. Optional, defaults to False.

  • resume_key – A resuming key which is passed to the provider server when connecting. Optional, defaults to None.

  • rest_url – The URL to the provider server’s REST API. Optional, if None (default), the URL will be constructed from the provided host and port.

  • ws_url – The URL to the provider server’s websocket. Optional, if None (default), the URL will be constructed from the provided host and port.

  • json_dumps – A callable which will be used to serialize JSON data. Optional, if None (default), json.dumps() will be used.

  • json_loads – A callable which will be used to deserialize JSON data. Optional, if None (default), json.loads() will be used.

  • spotify_client_id – The client ID from a Spotify API application. Optional, if None (default), Spotify integration will be disabled.

  • spotify_client_secret – The client secret from a Spotify API application. Optional, if None (default), Spotify integration will be disabled.

property bot: slate.types.BotT#

The bot instance that this node belongs to.

property rest_url: str#

The URL used for rest requests to the provider server.

property ws_url: str#

The URL used to connect to the provider server’s websocket.

property players: dict[int, PlayerT]#

A mapping of guild ID to player instance.

is_connected() bool#

Returns True if the node is connected to the provider server, False otherwise.

await connect(*, raise_on_failure: bool = False) None#

Connects this node to its provider server.

Parameters

raise_on_failure (bool) – Whether to raise an exception if the connection fails. Defaults to False.

await disconnect(*, force: bool = False) None#

Disconnects this node from its provider server.

Parameters

force (bool) – Whether to force disconnect players with Player.disconnect(). Defaults to False.

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 – The search query.

  • source – The source to request results from. Defaults to Source.NONE.

Raises

Player#

class slate.Player#
__init__(client: ~slate.types.BotT = <MISSING>, channel: discord.channel.VoiceChannel | discord.channel.StageChannel = <MISSING>, /, *, node: ~typing.Optional[~slate.node.Node[~slate.types.BotT, ~slate.types.PlayerT]] = None) None#
Parameters

node – The node this player should be attached to, if None the player will be attached to the first node found from the pool.

Warning

To connect to a voice channel you must construct an instance of this class, setting the node argument (and extras, if subclassing) but not the client or channel arguments. You can then pass it to the cls argument of discord.abc.Connectable.connect().

property bot: slate.types.BotT#

The bot this player is attached to.

property voice_channel: discord.channel.VoiceChannel | discord.channel.StageChannel#

The voice channel this player is connected to.

property node: slate.node.Node[slate.types.BotT, slate.types.PlayerT]#

The node this player is attached to.

property current_track_id: str | None#

The ID of the current track. This is None if no track is playing.

property current: slate.objects.track.Track | None#

The current track. This is None if no track is playing.

property paused: bool#

Whether the player is paused.

property position: float#

The position of the player. Returns 0 if no track is playing.

property filter: slate.objects.filters.filter.Filter | None#

The players current filter, if set.

property listeners: list[discord.member.Member]#

A list of members in the players voice channel.

Notes

This only returns non-bot members who are not deafened.

is_connected() bool#

Returns True if the player is connected to its voice channel, False otherwise.

is_playing() bool#

Returns True if the player is playing a track, False otherwise.

is_paused() bool#

Returns True if the player is paused, False otherwise.

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_muteTrue if the player should be muted when connected. Defaults to False.

  • self_deafTrue if the player should be deafened when connected. Defaults to True.

await disconnect(*, force: bool = False) None#

Disconnects the player from its voice channel and removed it from the node.

Parameters

forceTrue if the player should send a request to the provider server to stop the current track even if one is not playing. Defaults to False.

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_replaceTrue if this track should not replace the current track, if any. Defaults to False.

await stop(*, force: bool = False) None#

Stops the current track.

Parameters

forceTrue if the player should send the stop track request to the provider server even if this player’s current attribute is None. Defaults to False.

await set_pause(pause: bool, /) None#

Sets the players pause state.

Parameters

pauseTrue if the player should be paused, False otherwise.

await set_filter(filter: Filter, /, *, set_position: bool = True) None#

Sets the players filter.

Parameters
  • filter – The filter to set.

  • set_positionTrue if the player should set its position to the current position which applied filters instantly. Defaults to True.

await set_position(position: float, /, *, force: bool = False) None#

Sets the players position.

Parameters
  • position – The position to set, in milliseconds.

  • forceTrue if the player should send the set position request to the provider server even if this player’s current attribute is None. Defaults to False.

Queue#

class slate.Queue#
__init__() None#
property length: int#
is_empty() bool#
property loop_mode: slate.objects.enums.QueueLoopMode#
set_loop_mode(mode: QueueLoopMode, /) None#
get(position: int = 0, /, *, put_history: bool = True) Optional[Item]#
put(item: Item, /, *, position: Optional[int] = None) None#
extend(items: list[Item], /, *, position: Optional[int] = None) None#
await get_wait() Item#
get_history(position: int = 0, /) Optional[Item]#
put_history(item: Item, /, *, position: Optional[int] = None) None#
extend_history(items: list[Item], /, *, position: Optional[int] = None) None#
shuffle() None#
reverse() None#
clear() None#
reset() None#

Objects#

Track#

class slate.Track#
__init__(*, id: str, info: dict[str, Any], extras: Optional[dict[str, Any]] = None) None#
property artwork_url: str | None#
is_stream() bool#
is_seekable() bool#

Collection#

class slate.Collection#
__init__(*, info: dict[str, Any], tracks: list[dict[str, Any]], extras: Optional[dict[str, Any]] = None) None#
property name: str#
property url: str#
property selected_track: slate.objects.track.Track | int | None#
property tracks: list[slate.objects.track.Track]#
property source: slate.objects.enums.Source#

Events#

TrackStart#

class slate.TrackStart#
__init__(data: dict[str, Any]) None#
property track_id: str#

TrackEnd#

class slate.TrackEnd#
__init__(data: dict[str, Any]) None#
property track_id: str#
property reason: Literal['STOPPED', 'REPLACED', 'CLEANUP', 'LOAD_FAILED', 'FINISHED']#

TrackStuck#

class slate.TrackStuck#
__init__(data: dict[str, Any]) None#
property track_id: str#
property threshold_ms: int#

TrackException#

class slate.TrackException#
__init__(data: dict[str, Any]) None#
property track_id: str#
property message: str#
property cause: str#
property severity: Literal['COMMON', 'FAULT', 'SUSPICIOUS']#

WebsocketOpen#

class slate.WebsocketOpen#
__init__(data: dict[str, Any]) None#
property target: str#
property ssrc: int#

WebsocketClosed#

class slate.WebsocketClosed#
__init__(data: dict[str, Any]) None#
property code: int#
property reason: str#
property by_remote: bool#

Filters#

ChannelMix#

class slate.ChannelMix#
__init__(*, left_to_left: float = 1.0, left_to_right: float = 0.0, right_to_left: float = 0.0, right_to_right: float = 1.0) None#
classmethod mono() Self#
classmethod only_left() Self#
classmethod full_left() Self#
classmethod only_right() Self#
classmethod full_right() Self#
classmethod switch() Self#

Distortion#

class slate.Distortion#
__init__(*, sin_offset: float = 0.0, sin_scale: float = 1.0, cos_offset: float = 0.0, cos_scale: float = 1.0, tan_offset: float = 0.0, tan_scale: float = 1.0, offset: float = 0.0, scale: float = 1.0) None#

Equalizer#

class slate.Equalizer#
__init__(*, name: str = 'CustomEqualizer', bands: list[tuple[int, float]]) None#

Karaoke#

class slate.Karaoke#
__init__(*, level: float = 1.0, mono_level: float = 1.0, band: float = 220.0, band_width: float = 100.0) None#

LowPass#

class slate.LowPass#
__init__(*, smoothing: float = 20.0) None#

Rotation#

class slate.Rotation#
__init__(*, speed: float = 5.0) None#

Timescale#

class slate.Timescale#
__init__(*, pitch: float = 1.0, speed: float = 1.0, rate: float = 1.0) None#

Tremolo#

class slate.Tremolo#
__init__(*, frequency: float = 2.0, depth: float = 0.5) None#

Vibrato#

class slate.Vibrato#
__init__(*, frequency: float = 2.0, depth: float = 0.5) None#

Volume#

class slate.Volume#
__init__(*, level: float = 100.0) None#

Filter#

class slate.Filter#
__init__(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) None#

Enums#

Provider#

class slate.Provider#

An enumeration.

OBSIDIAN = 0#

QueueLoopMode#

class slate.QueueLoopMode#

An enumeration.

DISABLED = 0#
ALL = 1#
CURRENT = 2#

Source#

class slate.Source#

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#

SlateError#

exception slate.SlateError#
__new__(**kwargs)#
__init__(*args, **kwargs)#

NodeAlreadyExists#

exception slate.NodeAlreadyExists#
__new__(**kwargs)#
__init__(*args, **kwargs)#

NodeNotFound#

exception slate.NodeNotFound#
__new__(**kwargs)#
__init__(*args, **kwargs)#

NoNodesConnected#

exception slate.NoNodesConnected#
__new__(**kwargs)#
__init__(*args, **kwargs)#

NodeConnectionError#

exception slate.NodeConnectionError#
__new__(**kwargs)#
__init__(*args, **kwargs)#

InvalidNodePassword#

exception slate.InvalidNodePassword#
__new__(**kwargs)#
__init__(*args, **kwargs)#

NodeNotConnected#

exception slate.NodeNotConnected#
__new__(**kwargs)#
__init__(*args, **kwargs)#

HTTPError#

exception slate.HTTPError#
__init__(response: ClientResponse, message: str) None#
property response: aiohttp.client_reqrep.ClientResponse#
property message: str#

NoResultsFound#

exception slate.NoResultsFound#
__init__(*, search: str, source: Source, type: str) None#
property search: str#
property source: slate.objects.enums.Source#
property type: str#

SearchFailed#

exception slate.SearchFailed#
__init__(data: dict[str, Any]) None#
property message: str#
property severity: Literal['COMMON', 'FAULT', 'SUSPICIOUS']#

Utils#

SPOTIFY_URL_REGEX#

slate.SPOTIFY_URL_REGEX#

A regex that matches spotify URLs for tracks, albums, playlists, and artists.

MISSING#

slate.MISSING#

A sentinel value that is used to indicate a missing value with distinction from None.