Brozy123 commited on
Commit
55cf5d2
·
verified ·
1 Parent(s): ebde272

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +20 -2
index.js CHANGED
@@ -1495,9 +1495,18 @@ async function initialize() {
1495
  client.rest.setAgent(ultimateFix.dispatcher);
1496
  client.options.rest.api = currentApi;
1497
 
 
 
 
 
1498
  const testRes = await fetch(`${currentApi}/v10/users/@me`, {
1499
- headers: { Authorization: `Bot ${TOKEN}` }
 
 
 
 
1500
  }).catch(() => null);
 
1501
 
1502
  if (testRes && testRes.status === 401) {
1503
  console.error("[CRITICAL] The provided BOT_TOKEN is INVALID (Discord returned 401). Please check your HF Secrets!");
@@ -1505,8 +1514,17 @@ async function initialize() {
1505
  } else if (testRes && testRes.ok) {
1506
  console.log(`[*] Token is VALID on ${currentApi}. Proceeding to WebSocket handshake...`);
1507
  } else {
1508
- console.log(`[*] ${currentApi} skipped or blocked (Rate limited or IP banned). Rotating...`);
 
1509
  currentEndpointIndex = (currentEndpointIndex + 1) % DISCORD_ENDPOINTS.length;
 
 
 
 
 
 
 
 
1510
  }
1511
 
1512
  console.log(`[*] Attempting connection to Discord (Attempt ${retryCount}) using ${currentApi}...`);
 
1495
  client.rest.setAgent(ultimateFix.dispatcher);
1496
  client.options.rest.api = currentApi;
1497
 
1498
+ // Add a timeout to fetch to prevent hanging forever on a blocked IP
1499
+ const abort = new AbortController();
1500
+ const timeout = setTimeout(() => abort.abort(), 10000); // 10s timeout
1501
+
1502
  const testRes = await fetch(`${currentApi}/v10/users/@me`, {
1503
+ headers: {
1504
+ Authorization: `Bot ${TOKEN}`,
1505
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
1506
+ },
1507
+ signal: abort.signal
1508
  }).catch(() => null);
1509
+ clearTimeout(timeout);
1510
 
1511
  if (testRes && testRes.status === 401) {
1512
  console.error("[CRITICAL] The provided BOT_TOKEN is INVALID (Discord returned 401). Please check your HF Secrets!");
 
1514
  } else if (testRes && testRes.ok) {
1515
  console.log(`[*] Token is VALID on ${currentApi}. Proceeding to WebSocket handshake...`);
1516
  } else {
1517
+ const reason = testRes ? `HTTP ${testRes.status}` : "Connection Timeout";
1518
+ console.log(`[*] ${currentApi} skipped: ${reason}. Rotating endpoint...`);
1519
  currentEndpointIndex = (currentEndpointIndex + 1) % DISCORD_ENDPOINTS.length;
1520
+
1521
+ // If we've tried all endpoints, wait a bit before the next loop
1522
+ if (currentEndpointIndex === 0) {
1523
+ const waitTime = 5000 + (Math.random() * 5000);
1524
+ console.log(`[!] ALL endpoints blocked. Waiting ${Math.round(waitTime/1000)}s before next cycle...`);
1525
+ await new Promise(r => setTimeout(r, waitTime));
1526
+ }
1527
+ throw new Error("Endpoint verification failed");
1528
  }
1529
 
1530
  console.log(`[*] Attempting connection to Discord (Attempt ${retryCount}) using ${currentApi}...`);