-
Notifications
You must be signed in to change notification settings - Fork 360
/
main.py
53 lines (44 loc) · 1.66 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import sys
import json
import time
import requests
import websocket
from keep_alive import keep_alive
status = "online" #online/dnd/idle
GUILD_ID = ADD_YOUR_SERVER_ID_HERE
CHANNEL_ID = ADD_YOUR_CHANNEL_ID_HERE
SELF_MUTE = True
SELF_DEAF = False
usertoken = os.getenv("TOKEN")
if not usertoken:
print("[ERROR] Please add a token inside Secrets.")
sys.exit()
headers = {"Authorization": usertoken, "Content-Type": "application/json"}
validate = requests.get('https://canary.discordapp.com/api/v9/users/@me', headers=headers)
if validate.status_code != 200:
print("[ERROR] Your token might be invalid. Please check it again.")
sys.exit()
userinfo = requests.get('https://canary.discordapp.com/api/v9/users/@me', headers=headers).json()
username = userinfo["username"]
discriminator = userinfo["discriminator"]
userid = userinfo["id"]
def joiner(token, status):
ws = websocket.WebSocket()
ws.connect('wss:https://gateway.discord.gg/?v=9&encoding=json')
start = json.loads(ws.recv())
heartbeat = start['d']['heartbeat_interval']
auth = {"op": 2,"d": {"token": token,"properties": {"$os": "Windows 10","$browser": "Google Chrome","$device": "Windows"},"presence": {"status": status,"afk": False}},"s": None,"t": None}
vc = {"op": 4,"d": {"guild_id": GUILD_ID,"channel_id": CHANNEL_ID,"self_mute": SELF_MUTE,"self_deaf": SELF_DEAF}}
ws.send(json.dumps(auth))
ws.send(json.dumps(vc))
time.sleep(heartbeat / 1000)
ws.send(json.dumps({"op": 1,"d": None}))
def run_joiner():
os.system("clear")
print(f"Logged in as {username}#{discriminator} ({userid}).")
while True:
joiner(usertoken, status)
time.sleep(30)
keep_alive()
run_joiner()