Zyroxx66 commited on
Commit
00a5bec
·
verified ·
1 Parent(s): 7ec5f7b
Files changed (1) hide show
  1. main.py +35 -12
main.py CHANGED
@@ -2,12 +2,10 @@ import discord
2
  import os
3
  import asyncio
4
  from discord.ext import commands
5
- from dotenv import load_dotenv
6
  import webserver
7
  import socket
8
  import aiohttp
9
-
10
- load_dotenv()
11
 
12
  class Zyrobot(commands.Bot):
13
  def __init__(self):
@@ -19,23 +17,48 @@ class Zyrobot(commands.Bot):
19
  super().__init__(command_prefix="!", intents=intents)
20
 
21
  async def setup_hook(self):
22
- for filename in os.listdir('./cogs'):
23
- if filename.endswith('.py'):
24
- await self.load_extension(f'cogs.{filename[:-3]}')
 
 
 
 
 
 
25
  await self.tree.sync()
26
 
27
  bot = Zyrobot()
28
 
29
  async def run_bot():
30
- # THIS LINE FIXES THE "STUCK" / DNS ERROR ON HUGGING FACE
31
- connector = aiohttp.TCPConnector(family=socket.AF_INET)
32
- async with aiohttp.ClientSession(connector=connector) as session:
33
- bot.http.connector = connector
34
- await bot.start(os.getenv("API_TOKEN"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  if __name__ == "__main__":
37
  webserver.keep_alive()
38
  try:
39
  asyncio.run(run_bot())
 
 
40
  except Exception as e:
41
- print(f"Bot failed: {e}")
 
2
  import os
3
  import asyncio
4
  from discord.ext import commands
 
5
  import webserver
6
  import socket
7
  import aiohttp
8
+ from aiohttp.resolver import AsyncResolver
 
9
 
10
  class Zyrobot(commands.Bot):
11
  def __init__(self):
 
17
  super().__init__(command_prefix="!", intents=intents)
18
 
19
  async def setup_hook(self):
20
+ print("--- Booting Zyrobot Engine ---")
21
+ if os.path.exists('./cogs'):
22
+ for filename in os.listdir('./cogs'):
23
+ if filename.endswith('.py'):
24
+ try:
25
+ await self.load_extension(f'cogs.{filename[:-3]}')
26
+ print(f'✅ Loaded: {filename}')
27
+ except Exception as e:
28
+ print(f'❌ Failed {filename}: {e}')
29
  await self.tree.sync()
30
 
31
  bot = Zyrobot()
32
 
33
  async def run_bot():
34
+ # 1. WAIT for the Hugging Face network to actually turn on
35
+ print("⏳ Waiting 30 seconds for Hugging Face network to stabilize...")
36
+ await asyncio.sleep(30)
37
+
38
+ # 2. Setup a MANUAL DNS Resolver (Talks to Google 8.8.8.8)
39
+ # This bypasses the [No address associated with hostname] error
40
+ resolver = AsyncResolver(nameservers=["8.8.8.8", "8.8.4.4"])
41
+ connector = aiohttp.TCPConnector(resolver=resolver, family=socket.AF_INET)
42
+
43
+ try:
44
+ async with aiohttp.ClientSession(connector=connector) as session:
45
+ bot.http.connector = connector
46
+ token = os.getenv("API_TOKEN")
47
+ if not token:
48
+ print("❌ ERROR: API_TOKEN is missing from Secrets!")
49
+ return
50
+ await bot.start(token)
51
+ except Exception as e:
52
+ print(f"⚠️ Connection attempt failed: {e}")
53
+ print("🔄 Retrying in 15 seconds...")
54
+ await asyncio.sleep(15)
55
+ await run_bot() # Recursive retry
56
 
57
  if __name__ == "__main__":
58
  webserver.keep_alive()
59
  try:
60
  asyncio.run(run_bot())
61
+ except KeyboardInterrupt:
62
+ pass
63
  except Exception as e:
64
+ print(f"💀 Fatal Error: {e}")