APRK01 commited on
Commit Β·
9ba9cec
1
Parent(s): 9dabc42
Fix: Add login retry logic for DNS stability
Browse files88 unmodified lines899091929293949596979899100101102103104105106107108109110111112113114115116117118119120121122941231241251261279910010110210310410510610710810911011112888 unmodified lines// ββ Login βββββββββββββββββββββββββββββββββββββββββββββββββββββconst token = process.env.BOT_TOKEN;console.log(` π Token: ${token ? token.slice(0, 10) + '...' + token.slice(-5) : 'MISSING'}`);console.log(' β³ Connecting to Discord...');
async function startBot(retryCount = 0) { if (retryCount > 10) { console.error('β MAX RETRIES REACHED. Bot failed to connect.'); process.exit(1); }
console.log(` β³ Connecting to Discord... (Attempt ${retryCount + 1})`); const loginTimeout = setTimeout(() => { console.error('β LOGIN TIMED OUT after 60s β Discord gateway unreachable'); }, 60000);
try { await client.login(token); clearTimeout(loginTimeout); console.log(' β
Login promise resolved'); } catch (err) { clearTimeout(loginTimeout); console.error(`β LOGIN FAILED: ${err.message}`); if (err.message.includes('ENOTFOUND') || err.message.includes('EAI_AGAIN')) { console.log(' π‘ DNS/Network error detected. Retrying in 10s...'); setTimeout(() => startBot(retryCount + 1), 10000); } else { console.error(' β οΈ Non-network error. Exiting.'); process.exit(1); } }}
// Debug logging for Render network issues// Debug logging for network issuesclient.on('debug', (info) => { if (info.includes('Gateway')) console.log(`[DEBUG] ${info}`);});
const loginTimeout = setTimeout(() => { console.error('β LOGIN TIMED OUT after 60s β Discord gateway unreachable'); console.log('π‘ TIP: Render IPs are sometimes flagged by Discord. Try restarting the service or checking the region.');}, 60000);
client.login(token).then(() => { clearTimeout(loginTimeout); console.log(' β
Login promise resolved');}).catch(err => { clearTimeout(loginTimeout); console.error('β LOGIN FAILED:', err.message); process.exit(1);});startBot();src/index.js+32-15