- Added automatic reconnect after refreshing Twitch bot token.

- Added reattempt limit to prevent Twitch ratelimiting.
kami_dev
Kami 2025-02-02 12:39:53 +01:00
parent 095514d95d
commit a83e27c7ed
1 changed files with 20 additions and 12 deletions

View File

@ -120,15 +120,23 @@ class TwitchBot(commands.Bot):
"""
Run the Twitch bot, refreshing tokens if needed.
"""
retries = 0
while True:
if retries > 3:
self.log(f"Twitch bot failed to connect after {retries} attempts.", "CIRITCAL")
break # Break loop if repeatedly failing to connect to Twitch
try:
await self.start()
#while True:
# await self.refresh_access_token()
# await asyncio.sleep(10800) # Refresh every 3 hours
except Exception as e:
retries += 1
self.log(f"Twitch bot failed to start: {e}", "CRITICAL")
if "Invalid or unauthorized Access Token passed." in str(e):
try:
await self.refresh_access_token()
except Exception as e:
self.log(f"Unable to refresh Twitch token! Twitch bot will be offline!", "CRITICAL")
await asyncio.sleep(5) # Wait before retrying to authenticate