Songbird Bindings#
songbird.songbird module#
The Songbird Python/Rust bindings This module is written in Rust 🚀
- 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
Driverwith theset_configmethod.- 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 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 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 stop(self) None#
Stops playing audio from all sources.
- async unmute(self) None#
Unmutes the driver.
- exception songbird.songbird.FfmpegError#
- 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#
- class songbird.songbird.Rtp#
- csrc_count: int#
- csrc_list: List[int]#
- extension: int#
- marker#
- padding: int#
- payload: List[int]#
- sequence: int#
- ssrc: int#
- timestamp: int#
- version: int#
- exception songbird.songbird.SongbirdError#
- class songbird.songbird.Source#
-
- 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 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>#
- 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.
- 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_playermethod.- async make_playable(self) None#
Ready a track for playing if it is lazily initialised. This won’t matter until
Restartableis implemented.
- async pause(self) None#
- async play(self) None#
- async play_time(self) float#
Returns how long the track has been playing for.
- 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#
-
- 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
Restartableis 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.
- play_time: float#
- position: float#
- volume: float#
- exception songbird.songbird.UseAsyncConstructorError#
- class songbird.songbird.VoiceData#
- audio: Optional[List[int]]#
- payload_end_pad: int#
- payload_offset: int#
- exception songbird.songbird.YtdlError#
- async songbird.songbird.create_player(source: Source) Tuple[Track, TrackHandle]#
Creates a
TrackandTrackHandleobject. The track is used to play theTrackand the TrackHandle can be used to control it after it starts playing.