Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class authenticate:
- def __init__(self, token):
- self.token = token
- print("Opticord | Authenticating to the discord gateway")
- loop = asyncio.get_event_loop()
- loop.create_task(self.auth(token=self.token))
- async def auth(self, token):
- uri = 'wss://gateway.discord.gg/?v=9&encoding=json'
- headers = {
- 'Authorization': f'Bot {token}'
- }
- async with websockets.connect(uri, extra_headers=headers) as websocket:
- message = {
- 'op': 2,
- 'd': {
- 'token': token,
- 'intents': 513,
- 'properties': {
- '$os': 'linux',
- '$browser': 'my_library',
- '$device': 'my_library'
- }
- }
- }
- await websocket.send(json.dumps(message))
- async for message in websocket:
- data = json.loads(message)
- if data['op'] == 10:
- print("Opticord | Successfully Authenticated to discord gateway")
- elif data['op'] == 0 and data['t'] == 'READY':
- print("Opticord | Received READY event:", data['d'])
- # Handle the READY event here
- else:
- print("Opticord | Received unknown event:", data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement