Hello, I know how to use the refresh token to get a access token and run the bot however I am running a full stack web application and in my backend so would need to run my bot at all times without stopping the changing the access token myself. Is there a way for the bot to detect when the access token has expired and replace it automatically?
You could just have your backend make the requests to the Refresh Token endpoint, and then store the new access and refresh token, such as in a database, a file, whatever is suitable for your use case.
Then whenever it needs to connect, such as after a disconnect or when the app first starts up, it just gets the token from where you’ve stored them.
I’m not understanding what the issue is. Can you better describe your situation? Am I understanding correctly that you have a web component and a chat connection? You said you understand how to use refresh tokens and your question is about running forever without having to manually add a new token. Where is the issue?
I recommend checking the token’s expiration before reconnecting and refreshing it if it has expired.
I’m not familiar with twitchio, but a quick glance at the documentation suggests you should consider using Client.event_token_expired instead. It doesn’t look like there is another way to do it without hacking into twitchio’s internals but .