Songbird Bindings#

songbird.songbird module#

The Songbird Python/Rust bindings This module is written in Rust 🚀

class songbird.songbird.ClientConnect#
audio_ssrc: int#
user_id: int#
video_ssrc: int#
class songbird.songbird.Config#

Config objects are how you set a driver’s configuration.

Note

Changes in a Config object are only passed to the Driver with the set_config method.

crypto_mode#
decode_mode#
driver_timeout#
gateway_timeout#
preallocated_tracks#
retry_limit#
retry_strategy#
set_crypto_mode(self, crypto_mode: CryptoMode)#

Sets the crypto_mode for this config object.

set_decode_mode(self, decode_mode: DecodeMode)#

Sets the decode_mode for this config object. This is the encryping and decrypting behavior.

set_driver_retry(self, strategy: Strategy, retry_limit: Optional[int])#

Sets the driver_retry for this config_object.

set_driver_timeout(self, driver_timeout: Optional[float])#

Sets the driver_timeout for this config object.

set_gateway_timeout(self, gateway_timeout: Optional[float])#

Sets the timeout for joining a voice channel.

set_preallocated_tracks(self, preallocated_tracks: int)#

Sets the preallocated_tracks for this config object.

class songbird.songbird.ConnectData#
channel_id: int#
guild_id: int#
server: str#
session_id: str#
ssrc: int#
exception songbird.songbird.ConsumedSourceError#
exception songbird.songbird.CouldNotConnectToRTPError#
exception songbird.songbird.CouldNotOpenFileError#
class songbird.songbird.CryptoMode#

Variants of the XSalsa20Poly1305 encryption scheme.

Lite: CryptoMode = <builtins.CryptoMode object>#
Normal: CryptoMode = <builtins.CryptoMode object>#
Suffix: CryptoMode = <builtins.CryptoMode object>#
class songbird.songbird.DecodeMode#

The decode mode to use.

Decode: DecodeMode = <builtins.DecodeMode object>#
Decrypt: DecodeMode = <builtins.DecodeMode object>#
Pass: DecodeMode = <builtins.DecodeMode object>#
class songbird.songbird.DisconnectKind#
Connect: DisconnectKind = <builtins.DisconnectKind object>#
Reconnect: DisconnectKind = <builtins.DisconnectKind object>#
Runtime: DisconnectKind = <builtins.DisconnectKind object>#
class songbird.songbird.DisconnectReason#
AttemptDiscarded: DisconnectReason = <builtins.DisconnectReason object>#
Internal: DisconnectReason = <builtins.DisconnectReason object>#
Io: DisconnectReason = <builtins.DisconnectReason object>#
ProtocolViolation: DisconnectReason = <builtins.DisconnectReason object>#
TimedOut: DisconnectReason = <builtins.DisconnectReason object>#
WsClosed: DisconnectReason = <builtins.DisconnectReason object>#
class songbird.songbird.Driver#

A connection to the Discord Voice gateway. The connection info must be from a different library as Songbird doesn’t provide a regular Gateway connection.

async def main():
    driver = await Driver.create()
    await driver.connect(
        token=token,
        endpoint=endpoint,
        session_id=session_id,
        guild_id=guild_id,
        channel_id=channel_id,
        user_id=user_id
    )

See more examples in the example directory.

async add_event(self, event: Event, call: Callable[..., None]) None#
async connect(self, token: str, endpoint: str, session_id: str, guild_id: int, channel_id: int, user_id: int) None#

Connect to a voice channel

Parameters
  • token – Token recieved from the Discord gateway. This is not your bot token.

  • endpoint – Endpoint recieved from Discord gateway.

  • session_id – Session id recieved from Discord gateway.

  • guild_id – Guild id you want to connct to.

  • channel_id – Channel id you want to connect to.

  • user_id – User id of the current user.

async static create() Driver#

create(config: Optional[Config]) -> ‘None’ –

Creates a driver for this class. Drivers must be created in an event loop so it has to be done like this.

from songbird import Driver
...

driver = await Driver.create()
async get_config(self) Config#

Returns a copy of the config for this Driver

async is_muted(self) bool#

Returns whether the driver is muted.

async leave(self) None#

Disables the driver. This does not update your voice state to remove you from the voice channel.

async mute(self) None#

Mutes the driver.

async play(self, source: Track) TrackHandle#

Plays a Track object. This makes the Track object unuseable.

async play_only(self, source: Track) TrackHandle#

Same as play but stops all other sources from playing.

async play_only_source(self, source: Source) TrackHandle#

Same as play_source but stops all other sources from playing.

Raises

ConsumedSourceError – Source was already played or used to create a track object.

async play_source(self, source: Source) TrackHandle#

Plays a Playable object. Playable are activated when you try to play them. That means all errors are thrown in this method.

Raises

ConsumedSourceError – Source was already played or used to create a track object.

async remove_all_events(self) None#
async set_bitrate(self, bitrate: int) None#

Sets the bitrate to a i32

async set_bitrate_to_auto(self) None#

Sets the bitrate to Bitrate::Auto

async set_bitrate_to_max(self) None#

Sets the bitrate to a Bitrate::Max

async set_config(self, config: Config) None#

Set the config for this Driver

async stop(self) None#

Stops playing audio from all sources.

async unmute(self) None#

Unmutes the driver.

class songbird.songbird.Event#
ClientConnect = None#
ClientDisconnect: Event = <builtins.Event object>#
DriverConnect: Event = <builtins.Event object>#
DriverDisconnect: Event = <builtins.Event object>#
DriverReconnect: Event = <builtins.Event object>#
End: Event = <builtins.Event object>#
Loop: Event = <builtins.Event object>#
Pause: Event = <builtins.Event object>#
Play: Event = <builtins.Event object>#
RtcpPacket = <builtins.Event object>#
SpeakingStateUpdate: Event = <builtins.Event object>#
SpeakingUpdate: Event = <builtins.Event object>#
VoicePacket: Event = <builtins.Event object>#
static delayed(self, duration: float) Event#

Event fired after the delay value.

static periodic(self, duration: float, phase: Optional[float] = None) Event#

Repeats every duration.

exception songbird.songbird.FfmpegError#
class songbird.songbird.LoopCount#
loop_state: Optional[int]#
class songbird.songbird.Metadata#

The metadata for a track

track#

The track of this stream.

artist#

The main artist of the track.

date#

The date of creation of the stream.

channels#

The number of audio channels in the track. Any number >= 2 is treated as stereo.

channel#

The youtube channel for the track.

start_time#

The time at which playback was started.

duration#

The duration of the track.

sample_rate#

The sample rate of the track.

source_url#

The source url of the stream.

title#

The YouTube title of the track.

thumbnail#

The thumbnail url of this stream.

artist: Optional[str]#
channel: Optional[str]#
channels: Optional[int]#
date: Optional[str]#
duration: Optional[float]#
sample_rate: Optional[int]#
source_url: Optional[str]#
start_time: Optional[float]#
thumbnail: Optional[str]#
title: Optional[str]#
track: Optional[str]#
class songbird.songbird.PlayMode#
End: PlayMode = <builtins.PlayMode object>#
Pause: PlayMode = <builtins.PlayMode object>#
Play: PlayMode = <builtins.PlayMode object>#
Stop: PlayMode = <builtins.PlayMode object>#
class songbird.songbird.Rtp#
csrc_count: int#
csrc_list: List[int]#
extension: int#
marker#
padding: int#
payload: List[int]#
payload_type: RtpType#
sequence: int#
ssrc: int#
timestamp: int#
version: int#
class songbird.songbird.RtpType#
CelB: RtpType = <builtins.RtpType object>#
Cn: RtpType = <builtins.RtpType object>#
Dvi4_1: RtpType = <builtins.RtpType object>#
Dvi4_2: RtpType = <builtins.RtpType object>#
Dvi4_3: RtpType = <builtins.RtpType object>#
Dvi4_4: RtpType = <builtins.RtpType object>#
Dvi4_5: RtpType = <builtins.RtpType object>#
Dvi4_6: RtpType = <builtins.RtpType object>#
Dvi4_7: RtpType = <builtins.RtpType object>#
Dvi4_8: RtpType = <builtins.RtpType object>#
Dynamic_1: RtpType = <builtins.RtpType object>#
Dynamic_2: RtpType = <builtins.RtpType object>#
Dynamic_3: RtpType = <builtins.RtpType object>#
Dynamic_4: RtpType = <builtins.RtpType object>#
Dynamic_5: RtpType = <builtins.RtpType object>#
Dynamic_6: RtpType = <builtins.RtpType object>#
Dynamic_7: RtpType = <builtins.RtpType object>#
Dynamic_8: RtpType = <builtins.RtpType object>#
G722: RtpType = <builtins.RtpType object>#
G723: RtpType = <builtins.RtpType object>#
G728: RtpType = <builtins.RtpType object>#
G729: RtpType = <builtins.RtpType object>#
Gsm: RtpType = <builtins.RtpType object>#
H261 = <builtins.RtpType object>#
H263: RtpType = <builtins.RtpType object>#
Illegal_1: RtpType = <builtins.RtpType object>#
Illegal_2: RtpType = <builtins.RtpType object>#
Illegal_3: RtpType = <builtins.RtpType object>#
Illegal_4: RtpType = <builtins.RtpType object>#
Illegal_5: RtpType = <builtins.RtpType object>#
Illegal_6: RtpType = <builtins.RtpType object>#
Illegal_7: RtpType = <builtins.RtpType object>#
Illegal_8: RtpType = <builtins.RtpType object>#
Jpeg: RtpType = <builtins.RtpType object>#
L16Mono: RtpType = <builtins.RtpType object>#
L16Stereo: RtpType = <builtins.RtpType object>#
Lpc: RtpType = <builtins.RtpType object>#
Mp2t: RtpType = <builtins.RtpType object>#
Mpa: RtpType = <builtins.RtpType object>#
Mpv: RtpType = <builtins.RtpType object>#
Nv: RtpType = <builtins.RtpType object>#
Pcma: RtpType = <builtins.RtpType object>#
Pcmu: RtpType = <builtins.RtpType object>#
Qcelp: RtpType = <builtins.RtpType object>#
Reserved_1: RtpType = <builtins.RtpType object>#
Reserved_2: RtpType = <builtins.RtpType object>#
Reserved_3: RtpType = <builtins.RtpType object>#
Reserved_4: RtpType = <builtins.RtpType object>#
Reserved_5: RtpType = <builtins.RtpType object>#
Reserved_6: RtpType = <builtins.RtpType object>#
Reserved_7: RtpType = <builtins.RtpType object>#
Reserved_8: RtpType = <builtins.RtpType object>#
Unassigned_1: RtpType = <builtins.RtpType object>#
Unassigned_2: RtpType = <builtins.RtpType object>#
Unassigned_3: RtpType = <builtins.RtpType object>#
Unassigned_4: RtpType = <builtins.RtpType object>#
Unassigned_5: RtpType = <builtins.RtpType object>#
Unassigned_6: RtpType = <builtins.RtpType object>#
Unassigned_7: RtpType = <builtins.RtpType object>#
Unassigned_8: RtpType = <builtins.RtpType object>#
exception songbird.songbird.SongbirdError#
class songbird.songbird.Source#
static bytes(bytes: bytes, stereo: bool) Source#

Create a source from bytes.

async static ffmpeg(filename: str, pre_input_args=None, args=None) Source#

Function used to play most audio formats

await driver.play(Source.ffmpeg("song.mp3"))
static file(url: str) Source#

This plays the bytes from the file, DO NOT use for mp3s, etc ffmpeg should be used instead.

async metadata(self) Metadata#

Returns the Metadata for this source

async stereo(self) bool#

Returns whether the souce is stereo

async static ytdl(url: str) Source#

Use youtube dl to play a video from a URL

Example .. code-block:: python

await driver.play(Source.ytdl(”https://www.youtube.com/watch?v=n5n7CSGPzqw”))

class songbird.songbird.Speaking#
delay: Optional[int]#
speaking: SpeakingState#
ssrc: int#
user_id: Optional[int]#
class songbird.songbird.SpeakingState#
Microphone: SpeakingState = <builtins.SpeakingState object>#
Priority: SpeakingState = <builtins.SpeakingState object>#
Soundshare: SpeakingState = <builtins.SpeakingState object>#
class songbird.songbird.SpeakingUpdateData#
speaking: bool#
ssrc: int#
class songbird.songbird.Strategy#
static backoff(min: float, max: float, jitter: float) Strategy#

Exponential backoff waiting strategy. * min The minimum amount of time to wait between retries. * max Maximum amount of time to wait between retries. * jitter Random jitter applied to wait times. This is a percent. I.e. 0.1 will add +/-10% to generated intervals.

static backoff_default() Strategy#

Exponential backoff waiting strategy with default parameters.

static every(duration: float) Strategy#

Wait an even amount of time between each retry.

class songbird.songbird.Track#

A Track. This is similar to a Source but you can control audio before its played. This object should only be created through the create_player method.

async make_playable(self) None#

Ready a track for playing if it is lazily initialised. This won’t matter until Restartable is implemented.

async pause(self) None#
async play(self) None#
async play_time(self) float#

Returns how long the track has been playing for.

async playing(self) PlayMode#

Returns True if the track is playing.

async position(self) float#

Returns the position of the track.

async seek_time(self, position: float) float#

Seek to a specific point in the track.

async set_loop_count(self, loops: LoopCount) LoopCount#

Sets the loop count. If loops is None, it will loop forever.

async set_volume(self, volume: float) None#

Sets the volume of the track.

async state(self) TrackState#

Returns a copy of the track’s state.

async stop(self) None#

Manually stops a track. Stopped/ended tracks cannot be restarted.

async uuid(self) str#

Returns the track’s UUID.

async volume(self) None#

Returns the volume of the track.

exception songbird.songbird.TrackError#
class songbird.songbird.TrackHandle#
add_event(self, event: Event, call: Callable) None#

Adds an event to the track.

disable_loop(self) None#

Disables looping.

enable_loop(self) None#

Enables looping.

async get_info(self) TrackState#

Gets the TrackState for a track.

is_seekable#
loop_for(self, count: int) None#

Loops for a certain amount of times.

make_playable(self) None#

Makes a lazily initialized track playable. This does not matter to the current functionality of the lib because Restartable is not implemented.

metadata#
pause(self) None#

Unpauses the track.

play(self) None#

Stops the track from playing.

seek_time(self, position: float) float#

Seeks to a specific time in the track.

set_volume(self, volume: float) None#

Sets the volume of the track.

stop(self) None#

Stops the track. A track stopped with Stop cannot be restarted.

uuid#
class songbird.songbird.TrackState#

The state of the track.

loops: LoopCount#
play_time: float#
playing: PlayMode#
position: float#
volume: float#
exception songbird.songbird.UseAsyncConstructorError#
class songbird.songbird.VoiceData#
audio: Optional[List[int]]#
packet: Rtp#
payload_end_pad: int#
payload_offset: int#
exception songbird.songbird.YtdlError#
async songbird.songbird.create_player(source: Source) Tuple[Track, TrackHandle]#

Creates a Track and TrackHandle object. The track is used to play the Track and the TrackHandle can be used to control it after it starts playing.