问题描述
我希望当用户在某个列表上直播时,会向频道发送一条消息。但是,由于我将这部分代码放在 60 秒的异步循环中,因此我不确定如何执行此操作。它只是每 60 秒持续发布一次实时消息。
我尝试使用 If
语句并尝试使用变量,但是这只是继续进行而没有错误。
有谁知道某个功能可以让它只发布一次实时消息而不重复自己,直到用户的流再次离线?
谢谢,我的代码如下:
response = requests.get('https://api.twitch.tv/helix/search/channels',headers=headers,params=params)
final = response.json()
finali = final['data'][0]['is_live']
finale = final['data'][0]['thumbnail_url']
finaly = final['data'][0]['title']
finalo = final['data'][0]['started_at']
print(final)
async def live_poster():
if finali:
await client.wait_until_ready()
counter = 1
print("someone live")
channel = client.get_channel(channelid)
while not client.is_closed():
counter += 1
embedVar2 = discord.Embed(title="" + x + " is now live on Twitch!",description="" + finaly + "",url="https://twitch.tv/" + x + "",color=0x0C8BC2)
embedVar2.set_image(url="" + finale + "")
await channel.send("@everyone")
await channel.send(embed=embedVar2)
await asyncio.sleep(60) # task runs every 60 seconds
client.loop.create_task(live_poster())
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)