Python Async Programming: Getting Gift info with TikTokLive Library

61 views Asked by At

I am trying TikTokLive library to get the username who gives gift and feed to my GUI program. But I screwed up with how to use Async function.

TikTokLive Library https://github.com/isaackogan/TikTokLive

My code:

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

The program can run but the console does not show the username who gives gift. If I use the original example in TikTokLive, I can get the username.

0

There are 0 answers