Mas*_*tor 5 python parameter-passing twitch discord discord.py
所以我正在制作一个 Discord Bot,当一个人在 Twitch.tv 上直播时会发帖。目前,我有一个运行机器人的 Python 程序和一个运行微型服务器以从 Twitch 服务器(webhook)接收数据的程序。我不确定如何将从我的服务器收到的数据传递给不和谐机器人。两个程序必须同时运行。
不和谐机器人
import discord
client = discord.Client()
async def goes_live(data):
print(data)
print('Going Live')
msg = '--- has gone live'
await client.send_message(discord.Object(id='---'), msg)
@client.event
async def on_message(message):
if message.author == client.user:
return
message.content = message.content.casefold()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run('---')
Run Code Online (Sandbox Code Playgroud)
网络服务器
import web
urls = ('/.*', 'hooks')
app = web.application(urls, globals())
class hooks:
def POST(self):
data = web.data()
print("")
print('DATA RECEIVED:')
print(data)
print("")
return 'OK'
def GET(self):
try:
data = web.input()
data = data['hub.challenge']
print("Hub challenge: ", data)
return data
except KeyError:
return web.BadRequest
if __name__ == '__main__':
app.run()
Run Code Online (Sandbox Code Playgroud)