fix: bot stuck when forcefully disconnected without using command
This commit is contained in:
parent
f7d926bf2d
commit
44d798d1d2
1 changed files with 71 additions and 50 deletions
|
@ -31,7 +31,7 @@ async fn get_channel_info(ctx: &Context, voice_state: &VoiceState) -> Option<Gui
|
|||
Some(voice_channel)
|
||||
}
|
||||
|
||||
pub async fn handle_voice_update(ctx: Context, voice_state_old: VoiceState, voice_state: VoiceState) -> Option<()> {
|
||||
pub async fn handle_autodisconnect(ctx: Context, voice_state_old: VoiceState, voice_state: VoiceState) -> Option<()> {
|
||||
// Logic is as follows:
|
||||
// User connected -> voice_state_old is None (we handle this before this function)
|
||||
// Bot was moved to different vc -> we check if the new voice_state has the bot's user id
|
||||
|
@ -87,3 +87,24 @@ pub async fn handle_voice_update(ctx: Context, voice_state_old: VoiceState, voic
|
|||
|
||||
None
|
||||
}
|
||||
|
||||
pub async fn handle_voice_update(ctx: Context, voice_state_old: VoiceState, voice_state: VoiceState) -> Option<()> {
|
||||
// if the user was disconnected remove Songbird manager so it won't get stuck
|
||||
// Actually this is not really a bug since we can handle disconnect and therefore saving the song queue for example
|
||||
if voice_state.channel_id.is_none() && voice_state.user_id == ctx.cache.current_user().id {
|
||||
let manager = songbird::get(&ctx)
|
||||
.await
|
||||
.expect("Songbird Voice client placed in at initialisation.")
|
||||
.clone();
|
||||
|
||||
let guild_id = voice_state_old.guild_id?;
|
||||
// bot is not connected to any channel via songbird, don't need to do anything
|
||||
if manager.get(guild_id).is_some() {
|
||||
let _ = manager.remove(guild_id).await;
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
handle_autodisconnect(ctx, voice_state_old, voice_state).await?;
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue