43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
import asyncio
|
|
import websockets
|
|
import json
|
|
from enums import OpCode
|
|
|
|
TOKEN = "MTM0NjkyMDM5MjQ1MDc2ODk2OA.GUsapQ.LRdsHSQBfdDDMtr11jxkHpdY64-ugAeupLSM4A"
|
|
GATEWAY_URL = "wss://gateway.discord.gg/?v=10&encoding=json"
|
|
|
|
async def identify(websocket):
|
|
payload = {
|
|
"op": OpCode.IDENTIFY, # OpCode 2 = Identify
|
|
"d": {
|
|
"token": TOKEN,
|
|
"properties": {
|
|
"os": "windows",
|
|
"browser": "gambling",
|
|
"device": "gambling"
|
|
},
|
|
"intents": 513,
|
|
}
|
|
}
|
|
await websocket.send(json.dumps(payload))
|
|
|
|
async def heartbeat(websocket, interval):
|
|
while True:
|
|
await asyncio.sleep(interval / 1000)
|
|
await websocket.send(json.dumps({"op": OpCode.HEARTBEAT, "d": None}))
|
|
|
|
async def connect():
|
|
async with websockets.connect(GATEWAY_URL) as websocket:
|
|
response = json.loads(await websocket.recv())
|
|
heartbeat_interval = response["d"]["heartbeat_interval"]
|
|
|
|
asyncio.create_task(heartbeat(websocket, heartbeat_interval))
|
|
|
|
await identify(websocket)
|
|
|
|
while True:
|
|
message = json.loads(await websocket.recv())
|
|
print("Received: ", message)
|
|
|
|
asyncio.run(connect())
|