mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-20 16:00:29 +00:00
Actually use v4 gateway and fixes thanks to Jake.
This commit is contained in:
parent
c97e5a17e6
commit
f6fa1e837a
@ -26,7 +26,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
|
||||
BASE = 'https://discordapp.com'
|
||||
API_BASE = BASE + '/api'
|
||||
GATEWAY = API_BASE + '/gateway?encoding=json&v=4'
|
||||
GATEWAY = API_BASE + '/gateway'
|
||||
USERS = API_BASE + '/users'
|
||||
ME = USERS + '/@me'
|
||||
REGISTER = API_BASE + '/auth/register'
|
||||
|
@ -125,7 +125,7 @@ def get_gateway(token, *, loop=None):
|
||||
yield from resp.release()
|
||||
raise GatewayNotFound()
|
||||
data = yield from resp.json(encoding='utf-8')
|
||||
return data.get('url')
|
||||
return data.get('url') + '?encoding=json&v=4'
|
||||
|
||||
class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
||||
"""Implements a WebSocket for Discord's gateway v4.
|
||||
@ -310,6 +310,9 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
||||
if op == self.INVALIDATE_SESSION:
|
||||
state.sequence = None
|
||||
state.session_id = None
|
||||
if data == True:
|
||||
raise ResumeWebSocket()
|
||||
|
||||
yield from self.identify()
|
||||
return
|
||||
|
||||
@ -381,10 +384,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
||||
except websockets.exceptions.ConnectionClosed as e:
|
||||
if self._can_handle_close(e.code):
|
||||
log.info('Websocket closed with {0.code} ({0.reason}), attempting a reconnect.'.format(e))
|
||||
if e.code == 4006:
|
||||
raise ReconnectWebSocket() from e
|
||||
else:
|
||||
raise ResumeWebSocket() from e
|
||||
raise ResumeWebSocket() from e
|
||||
else:
|
||||
raise ConnectionClosed(e) from e
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user