discordapi.voice

Module Contents

Classes

DiscordVoiceClient

Base class for running WebSocket connection.

class discordapi.voice.DiscordVoiceClient(client, endpoint, token, session_id, server_id)

Bases: discordapi.websocket.WebSocketThread

Inheritance diagram of discordapi.voice.DiscordVoiceClient

Base class for running WebSocket connection.

It has .do_heartbeat, .init_connection, .cleanup method to be overriden by inherited client, for defining desired behaviour depending on clients.

This class inherits from Thread, and is running as a separate thread. To start the client, you have to invoke .start method as you would with typical threads.

url

URL of the gateway for this client to connect to.

dispatcher

Handler to be called when the event has been received. It should recieve a single argument with type of dict.

ready_to_run

Event object indicating if the event is ready to be used. This event must be set manually by the inherited class.

_sock

internal WebSocket object to be used to communicate with gateway.

heartbeat_thread

Thread where .do_heartbeat method runs. This thread runs throughout the lifetime of this thread, so .do_heartbeat should be written with continuability in mind.

init_thread

Thread where init_thread method runs. It runs in thread so that ._event_loop method could run parellelly. This thread is expected to run quick and quit shortly after.

Parameters
  • url – same as .url attribute

  • dispatcher – same as .dispatcher attribute

  • name – same as name argument in threading.Thread

IDENTIFY = 0
SELECT_PROTOCOL = 1
READY = 2
HEARTBEAT = 3
SESSION_DESCRIPTION = 4
SPEAKING = 5
HEARTBEAT_ACK = 6
RESUME = 7
HELLO = 8
RESUMED = 9
CLIENT_DISCONNECT = 13
_set_info(self, endpoint, token, session_id, server_id=None)
reapply_info(self, endpoint, token, session_id, server_id=None)
get_channel(self)
speak(self, speaking=1)

Send SPEAKING event to the gateway.

Parameters

speaking – either bool or integer. True indicates speaking, False indicates that the client is no longer speaking. integer value should be the flag value to be used. Default value is 1.

disconnect(self)
_send_voice(self, data)
xsalsa20_poly1305(self, header, data)
init_connection(self)

Method to be run when websocket connection establishes.

This method is expected to run shortly, if a problem occurs during the procedure, run .reconnect method which will reestablish the connection.

This method should be implemented by the inherited client.

send_identify(self)
ip_discovery(self)
send_udp(self, data)
send_protocol(self)
do_heartbeat(self)

Method to be run when websocket connection establishes.

This method runs throughout the main thread’s lifetime, so you should consider that while overriding the method.

This method should be implemented by the inherited class.

send_heartbeat(self)
_get_payload(self, op, d=None, **data)
cleanup(self)

Method to be called after the client disconnects.

This method exists to reset the attributes when needed. if not, you can just leave this method as is.

Whether to override this method or not is your choice.

_dispatcher(self, data)