Skip to content

Commit f80a897

Browse files
authored
Update main.py
1 parent 2c04884 commit f80a897

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

main.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import threading
2+
import asyncio
23
from bot.bot import bot
34
from web.app import app
45
from shared.config import DISCORD_TOKEN, ENABLE_LOGGING, BOT_STATUS, BOT_NAME
@@ -7,6 +8,21 @@
78
import time
89

910

11+
async def start_bot():
12+
retry_count = 0
13+
max_retries = 5
14+
15+
while retry_count < max_retries:
16+
try:
17+
await bot.start(DISCORD_TOKEN)
18+
except aiohttp.client_exceptions.ClientConnectorError as e:
19+
print(f"Connection error: {e}. Retrying in 10 seconds...")
20+
retry_count += 1
21+
await asyncio.sleep(10)
22+
except Exception as e:
23+
print(f"Unexpected error: {e}")
24+
break
25+
1026
def start_prometheus_server():
1127
# Start a Prometheus HTTP server on port 8000
1228
start_http_server(8000, addr='0.0.0.0')
@@ -46,4 +62,4 @@ async def on_disconnect():
4662
bot.load_extension('bot.news_feed')
4763
# bot.load_extension('bot.moderation') Turning off because it's not working
4864
start_prometheus_server()
49-
bot.run(DISCORD_TOKEN)
65+
asyncio.run(start_bot())

0 commit comments

Comments
 (0)