wpms commited on
Commit
471b4ce
·
verified ·
1 Parent(s): d00f353

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +23 -6
main.py CHANGED
@@ -24,7 +24,7 @@ def home():
24
  return "hey, bot started✅"
25
 
26
  def run_web():
27
- app.run(host='0.0.0.0', port=7860)
28
 
29
  # Start web server in a thread
30
  web_thread = Thread(target=run_web)
@@ -119,7 +119,6 @@ async def on_guild_remove(guild):
119
  async def help_command(interaction: discord.Interaction, command_name: str = None):
120
  """Show help information"""
121
  if command_name:
122
- # Show specific command help
123
  command_details = {
124
  "help": {
125
  "description": "Show all available commands or specific command help",
@@ -206,7 +205,6 @@ async def help_command(interaction: discord.Interaction, command_name: str = Non
206
  else:
207
  await interaction.response.send_message(f"❌ Command `/{command_name}` not found!", ephemeral=True)
208
  else:
209
- # Show all commands in chat
210
  embed = discord.Embed(
211
  title="🤖 Bot Commands",
212
  description="Here are all available slash commands:",
@@ -214,7 +212,6 @@ async def help_command(interaction: discord.Interaction, command_name: str = Non
214
  timestamp=datetime.now()
215
  )
216
 
217
- # Categorize commands
218
  categories = {
219
  "📁 General": [
220
  "`/help` - Show commands",
@@ -572,10 +569,30 @@ def get_uptime():
572
 
573
  return " ".join(parts)
574
 
575
- # Run the bot
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
576
  if __name__ == "__main__":
577
  try:
578
- bot.run(TOKEN)
579
  except Exception as e:
580
  logger.error(f"Failed to start bot: {e}")
581
  raise
 
24
  return "hey, bot started✅"
25
 
26
  def run_web():
27
+ app.run(host='0.0.0.0', port=3000)
28
 
29
  # Start web server in a thread
30
  web_thread = Thread(target=run_web)
 
119
  async def help_command(interaction: discord.Interaction, command_name: str = None):
120
  """Show help information"""
121
  if command_name:
 
122
  command_details = {
123
  "help": {
124
  "description": "Show all available commands or specific command help",
 
205
  else:
206
  await interaction.response.send_message(f"❌ Command `/{command_name}` not found!", ephemeral=True)
207
  else:
 
208
  embed = discord.Embed(
209
  title="🤖 Bot Commands",
210
  description="Here are all available slash commands:",
 
212
  timestamp=datetime.now()
213
  )
214
 
 
215
  categories = {
216
  "📁 General": [
217
  "`/help` - Show commands",
 
569
 
570
  return " ".join(parts)
571
 
572
+ # Retry function with exponential backoff
573
+ async def run_bot_with_retry():
574
+ max_retries = 10
575
+ retry_delay = 5
576
+
577
+ for attempt in range(1, max_retries + 1):
578
+ try:
579
+ logger.info(f"🚀 Attempting to start bot (attempt {attempt}/{max_retries})...")
580
+ await bot.start(TOKEN, reconnect=True)
581
+ break
582
+ except Exception as e:
583
+ logger.error(f"❌ Attempt {attempt} failed: {e}")
584
+ if attempt < max_retries:
585
+ wait_time = retry_delay * (2 ** (attempt - 1))
586
+ logger.info(f"⏳ Retrying in {wait_time} seconds...")
587
+ await asyncio.sleep(wait_time)
588
+ else:
589
+ logger.error("💥 Max retries reached. Bot failed to start.")
590
+ raise
591
+
592
+ # Run the bot with retry logic
593
  if __name__ == "__main__":
594
  try:
595
+ asyncio.run(run_bot_with_retry())
596
  except Exception as e:
597
  logger.error(f"Failed to start bot: {e}")
598
  raise