Skip to content

Commit

Permalink
fix(discord): reconnect when websocket connection is unexpectedly lost (
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueBrain authored Apr 9, 2024
1 parent 5c8d9f6 commit b2a1859
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion dibridge/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,13 @@ def update_presence(self, status):

def start(token, channel_id):
relay.DISCORD = RelayDiscord(channel_id)
relay.DISCORD.run(token, log_handler=None)
backoff = discord.backoff.ExponentialBackoff()

while True:
try:
relay.DISCORD.run(token, log_handler=None)
except Exception:
retry = backoff.delay()
log.exception("Discord client stopped unexpectedly; will reconnect in %.2f seconds", retry)

asyncio.run(asyncio.sleep(retry))

0 comments on commit b2a1859

Please sign in to comment.