pub struct Client { /* private fields */ }Expand description
The gateway client. Manages the WebSocket connection, heartbeating, reconnection, and event dispatch.
Call start to connect. It runs until a fatal error
happens (like an invalid token) and reconnects automatically on transient
failures.
Implementations§
Source§impl Client
impl Client
Sourcepub fn builder(token: impl Into<String>) -> ClientBuilder
pub fn builder(token: impl Into<String>) -> ClientBuilder
Examples found in repository?
examples/bot.rs (line 202)
198async fn main() {
199 let token = std::env::var("FLUXER_TOKEN")
200 .expect("Set FLUXER_TOKEN to your bot token");
201
202 let mut client = Client::builder(&token)
203 // .api_url("http://localhost:48763/api/v1") this is for self hosted instances
204 .event_handler(Handler)
205 .build();
206
207 if let Err(e) = client.start().await {
208 eprintln!("Error: {}", e);
209 }
210}More examples
examples/voice.rs (line 124)
115async fn main() {
116 let token = std::env::var("FLUXER_TOKEN")
117 .expect("Set FLUXER_TOKEN to your bot token");
118
119 let handler = Handler {
120 playback: Mutex::new(None),
121 voice: Mutex::new(None),
122 };
123
124 let mut client = Client::builder(&token)
125 // .api_url("http://localhost:48763/api/v1") this is for self hosted instances
126 .event_handler(handler)
127 .build();
128
129 if let Err(e) = client.start().await {
130 eprintln!("Error: {}", e);
131 }
132}Sourcepub async fn start(&mut self) -> Result<(), ClientError>
pub async fn start(&mut self) -> Result<(), ClientError>
Connects to the gateway and starts processing events. Blocks forever unless a fatal error occurs.
Examples found in repository?
examples/bot.rs (line 207)
198async fn main() {
199 let token = std::env::var("FLUXER_TOKEN")
200 .expect("Set FLUXER_TOKEN to your bot token");
201
202 let mut client = Client::builder(&token)
203 // .api_url("http://localhost:48763/api/v1") this is for self hosted instances
204 .event_handler(Handler)
205 .build();
206
207 if let Err(e) = client.start().await {
208 eprintln!("Error: {}", e);
209 }
210}More examples
examples/voice.rs (line 129)
115async fn main() {
116 let token = std::env::var("FLUXER_TOKEN")
117 .expect("Set FLUXER_TOKEN to your bot token");
118
119 let handler = Handler {
120 playback: Mutex::new(None),
121 voice: Mutex::new(None),
122 };
123
124 let mut client = Client::builder(&token)
125 // .api_url("http://localhost:48763/api/v1") this is for self hosted instances
126 .event_handler(handler)
127 .build();
128
129 if let Err(e) = client.start().await {
130 eprintln!("Error: {}", e);
131 }
132}Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more