From 7cbbe5c35437959627b089d33ccee29a792a7d03 Mon Sep 17 00:00:00 2001 From: jude-lafitteIII Date: Fri, 5 Jun 2020 17:43:03 +0100 Subject: [PATCH] moved disconnect loop to new thread to hopefully prevent shards dying --- src/main.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9c023b1..a4fa043 100644 --- a/src/main.rs +++ b/src/main.rs @@ -145,8 +145,6 @@ async fn role_check(ctx: &Context, msg: &Message, _args: &mut Args) -> CheckResu .collect::>() .join(", "); - println!("{}", user_roles); - let guild_id = *msg.guild_id.unwrap().as_u64(); let role_res = sqlx::query!( @@ -394,15 +392,15 @@ async fn main() -> Result<(), Box> { let cvm = Arc::clone(&client.voice_manager); - let disconnect_cycle_delay = env::var("DISCONNECT_CYCLE_DELAY") - .unwrap_or("300".to_string()) - .parse::()?; + tokio::spawn(async { + let disconnect_cycle_delay = env::var("DISCONNECT_CYCLE_DELAY") + .unwrap_or("300".to_string()) + .parse::().expect("DISCONNECT_CYCLE_DELAY invalid"); - // select on the client and client auto disconnector (when the client terminates, terminate the disconnector - tokio::select! { - _ = client.start_autosharded() => {} - _ = disconnect_from_inactive(cvm, voice_guilds, disconnect_cycle_delay) => {} - }; + disconnect_from_inactive(cvm, voice_guilds, disconnect_cycle_delay).await + }); + + client.start_autosharded().await?; Ok(()) }