Discord gateway seemingly not responding with `HELLO`

Viewed 154

I made a discord web hook using aiohttp (Python module) which first connects to the gateway and listens to it for any HELLO opcodes. The code labelled 1 shows my code for checking if the gateway responded with HELLO.

The code labelled 2 is my code for connecting to the gateway (ignore the print statements).

However, after checking my code multiple times, I did not find any errors; nor did I find any mistakes. Only these three bits of code shown are probably the reason, but why is this happening?

(The code labelled compression handles gateway binary compression)

By the way, I'm not rate limited nor am I banned from the discord gateway.

# Compression
if data.type == aiohttp.WSMsgType.BINARY:
    self.BUFFER.extend(data)

    # Payload compression handling
    if data[-4:] == self.ZLIB_SUFFIX:
        data = self.INFLATOR.decompress()

        # Transport compression handling, in which it uses regular compression,
        # without the extra compression to binary format.
    else:
        data = zlib.decompress(data)
...
# 1
if data.type == aiohttp.WSMsgType.TEXT or aiohttp.WSMsgType.BINARY:
    json_payload = json.loads(payload)

     # Finds the heartbeat_interval and send `IDENTIFY`!
     if json_payload["op"] == self.OPCODES["HELLO"]:
         self.heartbeat_interval = json_payload["d"]["heartbeat_interval"]

         identify_json = self.identify_request()
         await self.socket.send_json(# send the identify request)

...
# 2
async with aiohttp.ClientSession() as session:
    if self.socket:
    await self.socket.close()

    self.socket = await session.ws_connect(self.WSSGATEWAYURL)

    # We listen to socket before heartbeat to find heartbeat_interval
    await asyncio.gather(self.listen_to_socket(), self.keep_ws_alive())

Please take your time for reading this, and comment if you need any more code to help me! I really want help, thanks in advance <3

0 Answers
Related