提问人:idiot one 提问时间:11/9/2023 更新时间:11/9/2023 访问量:24
Python 异步编程:使用 TikTokLive 库获取礼物信息
Python Async Programming: Getting Gift info with TikTokLive Library
问:
我正在尝试 TikTokLive 库来获取向我的 GUI 程序赠送礼物和饲料的用户名。但是我搞砸了如何使用异步函数。
TikTokLive 图书馆 https://github.com/isaackogan/TikTokLive
我的代码:
from TikTokLive import TikTokLiveClient
from TikTokLive.types.events import CommentEvent, ConnectEvent, GiftEvent
from PyQt5.QtWidgets import QApplication
loop = asyncio.get_event_loop()
client: TikTokLiveClient = TikTokLiveClient(unique_id="@" + streamername, loop=loop)
@client.on("connect")
async def on_connect(_: ConnectEvent):
print("Connected to Room ID:", client.room_id)
async def on_comment(event: CommentEvent):
print(f"{event.user.nickname} -> {event.comment}")
client.add_listener("comment", on_comment)
async def main():
print("async main")
await client.start()
loop.run_until_complete(main())
app = QApplication(sys.argv)
# My rest GUI program that needs the username who gives gift
程序可以运行,但控制台不显示赠送礼物的用户名。如果我在 TikTokLive 中使用原始示例,我可以获得用户名。
答: 暂无答案
评论
loop.run_until_complete
不返回。您的 GUI 永远不会启动。右?