Spaces:
Runtime error
Runtime error
Update index.js
Browse files
index.js
CHANGED
|
@@ -31,7 +31,7 @@ const client = new Client({
|
|
| 31 |
],
|
| 32 |
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
|
| 33 |
rest: {
|
| 34 |
-
api:
|
| 35 |
version: '10',
|
| 36 |
timeout: 60000
|
| 37 |
},
|
|
@@ -1383,16 +1383,22 @@ async function initialize() {
|
|
| 1383 |
}
|
| 1384 |
|
| 1385 |
try {
|
| 1386 |
-
console.log(`[*] Attempting connection to Discord (Attempt ${retryCount + 1})...`);
|
| 1387 |
await client.login(TOKEN);
|
| 1388 |
} catch (err) {
|
| 1389 |
console.error(`[ERROR] Authentication Failed: ${err.message}`);
|
| 1390 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1391 |
// Exponential backoff for retries
|
| 1392 |
retryCount++;
|
| 1393 |
const delay = Math.min(1000 * Math.pow(2, retryCount), maxRetryDelay);
|
| 1394 |
|
| 1395 |
-
console.log(`[*] Retrying in ${delay / 1000}s...`);
|
| 1396 |
setTimeout(login, delay);
|
| 1397 |
}
|
| 1398 |
}
|
|
|
|
| 31 |
],
|
| 32 |
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
|
| 33 |
rest: {
|
| 34 |
+
api: `https://${networkFix.getTargetDomain()}/api`,
|
| 35 |
version: '10',
|
| 36 |
timeout: 60000
|
| 37 |
},
|
|
|
|
| 1383 |
}
|
| 1384 |
|
| 1385 |
try {
|
| 1386 |
+
console.log(`[*] Attempting connection to Discord (Attempt ${retryCount + 1}) on ${networkFix.getTargetDomain()}...`);
|
| 1387 |
await client.login(TOKEN);
|
| 1388 |
} catch (err) {
|
| 1389 |
console.error(`[ERROR] Authentication Failed: ${err.message}`);
|
| 1390 |
|
| 1391 |
+
// Professional Failover: Rotate endpoint and try again
|
| 1392 |
+
networkFix.rotateEndpoint();
|
| 1393 |
+
if (client.rest) {
|
| 1394 |
+
client.rest.options.api = `https://${networkFix.getTargetDomain()}/api`;
|
| 1395 |
+
}
|
| 1396 |
+
|
| 1397 |
// Exponential backoff for retries
|
| 1398 |
retryCount++;
|
| 1399 |
const delay = Math.min(1000 * Math.pow(2, retryCount), maxRetryDelay);
|
| 1400 |
|
| 1401 |
+
console.log(`[*] Retrying in ${delay / 1000}s with new route...`);
|
| 1402 |
setTimeout(login, delay);
|
| 1403 |
}
|
| 1404 |
}
|