Force disconnect in abc.Connectable.connect.
Some cases of is_connected is not set so we need to force it to clear it anyway.
This commit is contained in:
parent
cacd49b039
commit
64d09f3720
@ -940,7 +940,7 @@ class Connectable(metaclass=abc.ABCMeta):
|
|||||||
yield from voice.connect(reconnect=reconnect)
|
yield from voice.connect(reconnect=reconnect)
|
||||||
except asyncio.TimeoutError as e:
|
except asyncio.TimeoutError as e:
|
||||||
try:
|
try:
|
||||||
yield from voice.disconnect()
|
yield from voice.disconnect(force=True)
|
||||||
except:
|
except:
|
||||||
# we don't care if disconnect failed because connection failed
|
# we don't care if disconnect failed because connection failed
|
||||||
pass
|
pass
|
||||||
|
@ -81,7 +81,7 @@ class VoiceClient:
|
|||||||
The voice connection token.
|
The voice connection token.
|
||||||
endpoint: str
|
endpoint: str
|
||||||
The endpoint we are connecting to.
|
The endpoint we are connecting to.
|
||||||
channel: :class:`Channel`
|
channel: :class:`abc.Connectable`
|
||||||
The voice channel connected to.
|
The voice channel connected to.
|
||||||
loop
|
loop
|
||||||
The event loop that the voice client is running on.
|
The event loop that the voice client is running on.
|
||||||
@ -152,11 +152,13 @@ class VoiceClient:
|
|||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def terminate_handshake(self, *, remove=False):
|
def terminate_handshake(self, *, remove=False):
|
||||||
guild_id, _ = self.channel._get_voice_state_pair()
|
guild_id, channel_id = self.channel._get_voice_state_pair()
|
||||||
self._handshake_complete.clear()
|
self._handshake_complete.clear()
|
||||||
yield from self.main_ws.voice_state(guild_id, None, self_mute=True)
|
yield from self.main_ws.voice_state(guild_id, None, self_mute=True)
|
||||||
|
|
||||||
|
log.info('The voice handshake is being terminated for Channel ID %s (Guild ID %s)', channel_id, guild_id)
|
||||||
if remove:
|
if remove:
|
||||||
|
log.info('The voice client has been removed for Channel ID %s (Guild ID %s)', channel_id, guild_id)
|
||||||
key_id, _ = self.channel._get_voice_client_key()
|
key_id, _ = self.channel._get_voice_client_key()
|
||||||
self._state._remove_voice_client(key_id)
|
self._state._remove_voice_client(key_id)
|
||||||
|
|
||||||
@ -247,19 +249,21 @@ class VoiceClient:
|
|||||||
yield from self.connect(reconnect=True)
|
yield from self.connect(reconnect=True)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def disconnect(self):
|
def disconnect(self, *, force=False):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Disconnects all connections to the voice client.
|
Disconnects all connections to the voice client.
|
||||||
"""
|
"""
|
||||||
if not self._connected.is_set():
|
if not force and not self._connected.is_set():
|
||||||
return
|
return
|
||||||
|
|
||||||
self.stop()
|
self.stop()
|
||||||
self._connected.clear()
|
self._connected.clear()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield from self.ws.close()
|
if self.ws:
|
||||||
|
yield from self.ws.close()
|
||||||
|
|
||||||
yield from self.terminate_handshake(remove=True)
|
yield from self.terminate_handshake(remove=True)
|
||||||
finally:
|
finally:
|
||||||
if self.socket:
|
if self.socket:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user