APRK01 commited on
Commit Β·
9ba9cec
1
Parent(s): 9dabc42
Fix: Add login retry logic for DNS stability
Browse files88 unmodified lines899091929394959697989910010110210310410510610710810911011188 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...');// Debug logging for Render 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);});88 unmodified lines899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712888 unmodified lines// ββ Login βββββββββββββββββββββββββββββββββββββββββββββββββββββconst token = process.env.BOT_TOKEN;console.log(` π Token: ${token ? token.slice(0, 10) + '...' + token.slice(-5) : 'MISSING'}`);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 network issuesclient.on('debug', (info) => {if (info.includes('Gateway')) console.log(`[DEBUG] ${info}`);});startBot();
src/index.js+32-15