forked from Jmunb/discord-sender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (48 loc) · 1.45 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
54
55
56
import json
import os
import ssl
from datetime import datetime
from time import sleep, time
from urllib.parse import urlparse
import requests as req
import urllib3
from rich import print
from websocket import create_connection
urllib3.disable_warnings()
TOKEN = os.environ.get("DISCORD_TOKEN", "OTU3MjQ5Mzk0MDUzMzUzNTIz.Yj8FyQ.eyMLXxMqVXO4J5LphLMy1rOUTlk")
CHANNEL_ID = os.environ.get("DISCORD_CHANNEL_ID", "912053442397212712")
MESSAGE = os.environ.get("DISCORD_MESSAGE", "Hi, I'm Misha!")
def send(token, channel_id, message):
ws = None
ws = create_connection("wss://gateway.discord.gg/", sslopt={"cert_reqs": ssl.CERT_NONE})
data = '''
{
"op": 2,
"d":{
"token": "%s",
"properties": {
"$os": "linux",
"$browser": "ubuntu",
"$device": "ubuntu"
},
}
}
''' % token
ws.send(data)
try:
ws.close()
except:
pass
headers = {'authorization': token, 'Content-Type': 'application/json'}
payload = {"content":message,"tts":False}
req.post("https://discordapp.com/api/v9/channels/%s/messages" % channel_id,
headers = headers,
json=payload,
verify=False,
)
current_datetime = datetime.now()
print(f"{current_datetime} | MSG sended to {channel_id}")
if __name__ == "__main__":
send(token=TOKEN,
channel_id=CHANNEL_ID,
message=MESSAGE)