Advertisement
tommarek_CZE

Untitled

Feb 16th, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. class authenticate:
  2. def __init__(self, token):
  3. self.token = token
  4. print("Opticord | Authenticating to the discord gateway")
  5. loop = asyncio.get_event_loop()
  6. loop.create_task(self.auth(token=self.token))
  7.  
  8. async def auth(self, token):
  9. uri = 'wss://gateway.discord.gg/?v=9&encoding=json'
  10. headers = {
  11. 'Authorization': f'Bot {token}'
  12. }
  13.  
  14. async with websockets.connect(uri, extra_headers=headers) as websocket:
  15. message = {
  16. 'op': 2,
  17. 'd': {
  18. 'token': token,
  19. 'intents': 513,
  20. 'properties': {
  21. '$os': 'linux',
  22. '$browser': 'my_library',
  23. '$device': 'my_library'
  24. }
  25. }
  26. }
  27. await websocket.send(json.dumps(message))
  28.  
  29. async for message in websocket:
  30. data = json.loads(message)
  31.  
  32. if data['op'] == 10:
  33. print("Opticord | Successfully Authenticated to discord gateway")
  34. elif data['op'] == 0 and data['t'] == 'READY':
  35. print("Opticord | Received READY event:", data['d'])
  36. # Handle the READY event here
  37. else:
  38. print("Opticord | Received unknown event:", data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement