Uncategorized

Python twitchAPI.eventsub – Notification when streamers go live – API



I’m trying to build a custom Discord bot and part of the functionality I’m working on is being able to set up notifications for when streamers go live. I have been looking for different methods and libraries and tried using this to little success

https://pytwitchapi.dev/en/v2.4.0/modules/twitchAPI.eventsub.html

Below is my current code

from twitchAPI.twitch import Twitch
from twitchAPI import eventsub
import asyncio

class twitch_class:
    twitch = {}
    chat = {}
    app_id = ""
    app_secret = ""

    def __init__(self, app_id, app_secret) -> None:
        self.app_id = app_id
        self.app_secret = app_secret
        asyncio.run(self.create_socket_connection())

    async def create_socket_connection(self):
        self.twitch = await Twitch(self.app_id, self.app_secret)
        hook = eventsub("MyIP:Port", self.app_id, Port, self.twitch)
        hook.unsubscribe_all()
        hook.start()
        hook.listen_stream_online(Channel_ID, self.streamer_goes_live)
        #Lakea Channel ID - 
        #self.twitch.authenticate_app([])
        #events = twitchAPI.eventsub(self.twitch)
        print("RTEST")
        #eventsub.start()
        #self.chat = await Chat(self.twitch)

    async def streamer_goes_live(self, data: dict):
        print("TEST")
        print(data)

If I could have some explanation to help then it would be appreciated, I have looked at the Twitch documentation but thought this library handled the requests for me.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *