lavasnek_rs.lavasnek_rs

Cheat Sheet:

  • Functions that return a Result<T, E> mean that it can raise an exception. T is the type they return normally, and E is a list of possible exceptions that can raise.
  • Functions that return an Option<T> mean that the value returned can be None, where T would be the type of the returned value if not None.
  • If something returns a Future<T>, it means that it returns this, and that function should be awaited to work.
  • / on arguments means the end of positional arguments.
  • Self (with a capital S) means the type of self.
  • A type prefixed with impl means it's a Class that implements that Trait type.
#   def rust_sleep(seconds, /):

Test function, do not use.

#   def log_something():

Test function, do not use.

#   class LavalinkBuilder:

__new__()

All of the methods that return Self also modify Self, so you can chain them, or call the individually.

Positional Arguments:

  • bot_id : Unsigned 64 bit integer
  • bot_token : String

Returns: Self

#   LavalinkBuilder()
#   def build(self, event_handler, /):

Uses the Self data to build a Lavalink client and return it.

Can raise an exception if it's unable to connect to the lavalink server, discord server, or both.

Positional Arguments:

  • event_handler : impl LavalinkEventHandler

Returns: Future<Result<Lavalink, builtins.ConnectionError>>

#   def set_host(self, host, /):

Sets the host. (Default to: 127.0.0.1)

Positional Arguments:

  • host : String

Returns: Self

#   def set_port(self, port, /):

Sets the port. (Default to: 2333)

Positional Arguments:

  • port : Unsigned 16 bit integer

Returns: Self

#   def set_addr(self, address, /):

Sets the host and port from an address.

Can raise an exception if the address is an invalid IPv4 or IPv6.

Positional Arguments:

  • address : String

Returns: Result<Self, ipaddress.AddressValueError>

#   def set_password(self, password, /):

Sets the lavalink password. (Default to: "youshallnotpass")

Positional Arguments:

  • password : String

Returns: Self

#   def set_shard_count(self, shard_count, /):

Sets the number of shards. (Default to: 1)

Positional Arguments:

  • shard_count : Unsigned 64 bit integer

Returns: Self

#   def set_bot_id(self, bot_id, /):

Sets the ID of the bot.

Positional Arguments:

  • bot_id : Unsigned 64 bit integer

Returns: Self

#   def set_bot_token(self, bot_token, /):

Sets the token of the bot.

Positional Arguments:

  • bot_token : String

Returns: Self

#   def set_is_ssl(self, is_ssl, /):

Sets if the lavalink server is behind SSL. (Default to: False)

Positional Arguments:

  • is_ssl : bool

Returns: Self

#   def set_start_gateway(self, start_gateway, /):

Sets if the discord gateway for voice connections should start or not. (Default to: True)

Positional Arguments:

  • start_gateway : bool

Returns: Self

#   def set_gateway_start_wait_time_secs(self, time, /):

Sets the time to wait before starting the first discord gateway connection. (Default to: 6 seconds)

Positional Arguments:

  • time : Unsigned 64 bit integer

Returns: Self

#   def set_gateway_start_wait_time_millis(self, time, /):

Sets the time to wait before starting the first discord gateway connection.

Positional Arguments:

  • time : Unsigned 64 bit integer

Returns: Self

#   class PlayBuilder:
#   PlayBuilder()
#   def start(self, /):

Starts playing the track.

Returns: Future<Result<None, lavasnek_rs.NetworkError>>

#   def queue(self, /):

Adds the track to the node queue.

If there's no queue loop running, this will start one up, and add it to the running loops on Lavalink.loops()

Needs for `Lavalink.create_session() to be called first.

Returns: Future<Result<None, [lavasnek_rs.NoSessionPresent, lavasnek_rs.NetworkError]>>

#   def to_track_queue(self, /):

Generates a TrackQueue from the builder.

Returns: TrackQueue

#   def requester(self, requester, /):

Sets the person that requested the song

Positional Arguments:

  • requester : Unsigned 64 bit integer (User ID)

Returns: Self

#   def replace(self, replace, /):

Sets if the current playing track should be replaced with this new one.

Positional Arguments:

Returns: Self

#   def start_time_secs(self, start, /):

Sets the time the track will start at in seconds.

Positional Arguments:

  • start : Unsigned 64 bit integer

Returns: Self

#   def finish_time_secs(self, finish, /):

Sets the time the track will finish at in seconds.

Positional Arguments:

  • finish : Unsigned 64 bit integer

Returns: Self

#   def start_time_millis(self, start, /):

Sets the time the track will start at in milliseconds.

Positional Arguments:

  • start : Unsigned 64 bit integer

Returns: Self

#   def finish_time_millis(self, finish, /):

Sets the time the track will finish at in milliseconds.

Positional Arguments:

  • finish : Unsigned 64 bit integer

Returns: Self

#   class LavalinkEventHandler:

The lavalink event handler. This is a trait, so it defines the structure a class should have.

Make a class with the methods and signatures this class defines, and add that class to LavalinkBuilder.build()

If code inside any of the event raises an error, the traceback will be printed to stderr, and the variables sys.last_type, sys.last_value and sys.last_traceback will be set to the type, value and traceback of the printed exception respectively.

Some examples:

# Just a single event
class EventHandler:
    async def track_start(self, lava_client, event):
        print(event)

lavalink_client = await client_builder.build(EventHandler)
# No events
class EventHandler:
    pass

lavalink_client = await client_builder.build(EventHandler)
# Just a single event
class EventHandler:
    async def stats(self, lava_client, event):
        print(event)
    async def player_update(self, lava_client, event):
        print(event)
    async def track_start(self, lava_client, event):
        print(event)
    async def track_finish(self, lava_client, event):
        print(event)
    async def track_exception(self, lava_client, event):
        print(event)
    async def track_stuck(self, lava_client, event):
        print(event)
    async def websocket_closed(self, lava_client, event):
        print(event)
    async def player_destroyed(self, lava_client, event):
        print(event)

lavalink_client = await client_builder.build(EventHandler)
#   LavalinkEventHandler()
#   def stats(self, client, event, /):

Periodic event that returns the statistics of the server.

Positional Arguments:

Returns: Future<None>

#   def player_update(self, client, event, /):

Event that triggers when a player updates.

Positional Arguments:

Returns: Future<None>

#   def track_start(self, client, event, /):

Event that triggers when a track starts playing.

Positional Arguments:

Returns: Future<None>

#   def track_finish(self, client, event, /):

Event that triggers when a track finishes playing.

Positional Arguments:

Returns: Future<None>

#   def track_exception(self, client, event, /):

Event that triggers when a track raises an exception on the Lavalink server.

Positional Arguments:

Returns: Future<None>

#   def track_stuck(self, client, event, /):

Event that triggers when a track gets stuck while playing.

Positional Arguments:

Returns: Future<None>

#   def websocket_closed(self, client, event, /):

Event that triggers when the websocket connection to the voice channel closes.

Positional Arguments:

Returns: Future<None>

#   def player_destroyed(self, client, event, /):

Event that triggers when the player gets destroyed on a guild.

Positional Arguments:

Returns: Future<None>

#   class ConnectionInfo:

This is never actually used, a dictionary is used instead. If you use a 3rd party method of joining a voice channel, you can get this values from the VOICE_STATE_UPDATE and VOICE_SERVER_UPDATE events, and use raw_handle_event_voice_state_update() + raw_handle_event_voice_server_update() or manually build a dict with them.

With hikari:

@bot.listen()
async def voice_state_update(event: hikari.VoiceStateUpdateEvent) -> None:
    await bot.data.lavalink.raw_handle_event_voice_state_update(
        event.state.guild_id,
        event.state.user_id,
        event.state.session_id,
        event.state.channel_id,
    )

@bot.listen()
async def voice_server_update(event: hikari.VoiceServerUpdateEvent) -> None:
    await bot.data.lavalink.raw_handle_event_voice_server_update(
        event.guild_id, event.endpoint, event.token
    )

Fields:

  • guild_id : Unsigned 64 bit integer
  • channel_id : Unsigned 64 bit integer
  • endpoint : String
  • token : String
  • session_id : String
#   ConnectionInfo()
#   class Track:
#   Track()
#   track

The playable track.

Contains String

#   info

Information about the track.

Contains Option<Info>

#   class Tracks:
#   Tracks()
#   load_type

Contains String

#   tracks

The tracks that can be played

Contains List<Track>

#   playlist_info

Information about the playlist.

Contains Option<PlaylistInfo>

#   class TrackQueue:
#   TrackQueue()
#   start_time

The time the track will start at.

Contains Unsigned 64 bit integer

#   end_time

The time the track will finish at.

Contains Option<Unsigned 64 bit integer>

#   requester

The user id who requested the track if set by the PlayBuilder

Contains Option<Unsigned 64 bit integer>

#   track

The playable track.

Contains Track

#   class Info:
#   Info()
#   length

Contains Unsigned 64 bit integer

#   uri

Contains String

#   is_stream

Contains bool

#   is_seekable

Contains bool

#   title

Contains String

#   author

Contains String

#   identifier

Contains String

#   position

Contains Unsigned 64 bit integer

#   class PlaylistInfo:
#   PlaylistInfo()
#   selected_track

Contains Option<Signed 64 bit integer>

#   name

The name of the playlist.

Contains Option<String>

#   class Node:
#   Node()
#   def get_data(self, /):

Use this to get the currently stored data on the Node.

T is whatever type you give to set_data's data parameter, but if you call this method before it, it will default to a Dict.

Returns Future<T>

#   def set_data(self, data, /):

Use this to set the tored data of the Node.

Returns Future<None>

#   guild

Contains Unsigned 64 bit integer

#   volume

Contains Unsigned 16 bit integer

#   is_paused

Contains bool

#   is_on_loops

Contains bool

#   now_playing

Contains Option<TrackQueue>

#   queue

Contains List<TrackQueue>

#   class Band:

See Lavalink.equalize_all for more info.

band_num: int = 14 # 0 to 14
bain: float = 0.125 # -0.25 to 1.0

band = Band(band_num, gain)
#   Band()
#   gain

Contains 64 bit float

#   band

Contains Unsigned 8 bit integer

#   class Stats:
#   Stats()
#   frame_stats_sent

Contains Optional Signed 64 bit integer

#   playing_players

Contains Signed 64 bit integer

#   uptime

Contains Signed 64 bit integer

#   cpu_system_load

Contains 64 bit floating point

#   frame_stats_deficit

Contains Optional Signed 64 bit integer

#   memory_allocated

Contains Signed 64 bit integer

#   frame_stats_nulled

Contains Optional Signed 64 bit integer

#   op

Contains String

#   memory_reservable

Contains Signed 64 bit integer

#   memory_used

Contains Signed 64 bit integer

#   players

Contains Signed 64 bit integer

#   memory_free

Contains Signed 64 bit integer

#   cpu_cores

Contains Signed 64 bit integer

#   class PlayerUpdate:
#   PlayerUpdate()
#   guild_id

Contains Unsigned 64 bit integer

#   state_time

Contains Signed 64 bit integer

#   op

Contains String

#   state_position

Contains Signed 64 bit integer

#   class TrackStart:
#   TrackStart()
#   track

Contains String

#   op

Contains String

#   guild_id

Contains Unsigned 64 bit integer

#   track_start_type

Contains String

#   class TrackFinish:
#   TrackFinish()
#   reason

Contains String

#   guild_id

Contains Unsigned 64 bit integer

#   op

Contains String

#   track_finish_type

Contains String

#   track

Contains String

#   class TrackException:
#   TrackException()
#   guild_id

Contains Unsigned 64 bit integer

#   track_exception_type

Contains String

#   op

Contains String

#   track

Contains String

#   error

Contains String

#   exception_severity

Contains String

#   exception_cause

Contains String

#   exception_message

Contains String

#   class TrackStuck:
#   TrackStuck()
#   op

Contains String

#   threshold_ms

Contains Unsigned 64 bit integer

#   track

Contains String

#   guild_id

Contains Unsigned 64 bit integer

#   track_stuck_type

Contains String

#   class WebSocketClosed:
#   WebSocketClosed()
#   websocket_closed_type

Contains String

#   code

Contains Unsigned 64 bit integer

#   guild_id

Contains Unsigned 64 bit integer

#   user_id

Contains Unsigned 64 bit integer

#   op

Contains String

#   by_remote

Contains bool

#   class PlayerDestroyed:
#   PlayerDestroyed()
#   cleanup

Contains bool

#   op

Contains String

#   guild_id

Contains Unsigned 64 bit integer

#   user_id

Contains Unsigned 64 bit integer

#   player_destroyed_type

Contains String

#   class NoSessionPresent(builtins.Exception):

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
args
#   class NetworkError(builtins.Exception):

Common base class for all non-exit exceptions.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
args