-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
56 lines (40 loc) · 1.3 KB
/
test.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
from flask import Flask
from threading import Thread
import discord
import asyncio
app = Flask(__name__)
app.debug = False
class MyClient(discord.Client):
def hello_world(self):
return 'Username: {0.name}\nID: {0.id}'.format(self.user)
async def on_ready(self):
print('Connected!')
print('Username: {0.name}\nID: {0.id}'.format(self.user))
async def on_message(self, message):
if message.content.startswith('!editme'):
msg = await message.channel.send('10')
await asyncio.sleep(3.0)
await msg.edit(content='40')
async def on_message_edit(self, before, after):
fmt = '**{0.author}** edited their message:\n{0.content} -> {1.content}'
await before.channel.send(fmt.format(before, after))
client = MyClient()
@app.route('/')
def hello_world():
return '<a href="/ping">a</div>'
@app.route('/ping')
def ping():
return client.hello_world()
def startFlask():
app.run()
def startDiscord():
with open("auth.json") as auth:
client.run(json.load(auth)['TOKEN'])
if __name__ == "__main__":
flask_thread = Thread(target=startFlask)
flask_thread.start()
print('started flask')
discord_thread = Thread(target=startDiscord)
discord_thread.start()
print('started discord')