Brozy123 commited on
Commit
402ded7
·
verified ·
1 Parent(s): 4bb34db

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +16 -2
index.js CHANGED
@@ -1327,7 +1327,21 @@ async function showAutoFriendlyPanel(interaction) {
1327
  }
1328
 
1329
  server.startServer(client, commandsData);
1330
- client.on('error', (e) => console.error(e));
 
 
 
 
 
 
 
 
 
 
 
1331
  client.login(TOKEN).catch(e => {
1332
- console.error(`[!] Login Failed: Check your BOT_TOKEN in .env or HF Secrets.`);
 
 
 
1333
  });
 
1327
  }
1328
 
1329
  server.startServer(client, commandsData);
1330
+ client.on('error', (e) => {
1331
+ console.error(`[!] Client Error: ${e.message}`);
1332
+ if (e.message.includes('Timeout') || e.message.includes('UND_ERR') || e.message.includes('Connect')) {
1333
+ console.log("[*] Network failure detected. Rotating Discord endpoint...");
1334
+ networkFix.rotateEndpoint();
1335
+ // Dynamically update the REST API URL for future requests
1336
+ if (client.rest) {
1337
+ client.rest.options.api = `https://${networkFix.getTargetDomain()}/api`;
1338
+ }
1339
+ }
1340
+ });
1341
+
1342
  client.login(TOKEN).catch(e => {
1343
+ console.error(`[!] Login Failed: ${e.message}`);
1344
+ console.log("[*] Retrying login with rotated endpoint...");
1345
+ networkFix.rotateEndpoint();
1346
+ setTimeout(() => client.login(TOKEN).catch(() => {}), 5000);
1347
  });