Struct discord::Connection
[−]
[src]
pub struct Connection { /* fields omitted */ }
Websocket connection to the Discord servers.
Methods
impl Connection
[src]
fn new(
base_url: &str,
token: &str,
shard_info: Option<[u8; 2]>
) -> Result<(Connection, ReadyEvent)>
base_url: &str,
token: &str,
shard_info: Option<[u8; 2]>
) -> Result<(Connection, ReadyEvent)>
Establish a connection to the Discord websocket servers.
Returns both the Connection
and the ReadyEvent
which is always the
first event received and contains initial state information.
Usually called internally by Discord::connect
, which provides both
the token and URL and an optional user-given shard ID and total shard
count.
fn set_game(&self, game: Option<Game>)
Change the game information that this client reports as playing.
fn set_game_name(&self, name: String)
Set the client to be playing this game, with defaults used for any extended information.
fn set_presence(&self, game: Option<Game>, status: OnlineStatus, afk: bool)
Sets the active presence of the client, including game and/or status information.
afk
will help Discord determine where to send notifications.
fn voice(&mut self, server_id: Option<ServerId>) -> &mut VoiceConnection
Get a handle to the voice connection for a server.
Pass None
to get the handle for group and one-on-one calls.
fn drop_voice(&mut self, server_id: Option<ServerId>)
Drop the voice connection for a server, forgetting all settings.
Calling .voice(server_id).disconnect()
will disconnect from voice but retain the mute
and deaf status, audio source, and audio receiver.
Pass None
to drop the connection for group and one-on-one calls.
fn recv_event(&mut self) -> Result<Event>
Receive an event over the websocket, blocking until one is available.
fn shutdown(self) -> Result<()>
Cleanly shut down the websocket connection. Optional.
fn sync_servers(&self, servers: &[ServerId])
Requests a download of online member lists.
It is recommended to avoid calling this method until the online member list is actually needed, especially for large servers, in order to save bandwidth and memory.
Can be used with State::all_servers
.
fn sync_calls(&self, channels: &[ChannelId])
Request a synchronize of active calls for the specified channels.
Can be used with State::all_private_channels
.
fn download_all_members(&mut self, state: &mut State)
Requests a download of all member information for large servers.
The members lists are cleared on call, and then refilled as chunks are received. When
unknown_members()
returns 0, the download has completed.