From 045abde6068c6418b3690565ed9d4bb5af5a221e Mon Sep 17 00:00:00 2001 From: Cristiano Pires Date: Wed, 3 May 2023 19:05:55 +0100 Subject: [PATCH] Rate limit protection --- server.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index ef844cc..7bc152c 100644 --- a/server.js +++ b/server.js @@ -49,11 +49,24 @@ const bot = new Client({ intents: [ Partials.Message ] }); +var retryCounter = 0; (function login() { - bot.login(process.env.discord_token).catch(()=>{login()}); + bot.login(process.env.discord_token).catch(()=> + { + if(retryCounter==900) return startLimitProtectionTimer(); + login(); + retryCounter++; + }); })() - +function startLimitProtectionTimer() +{ + console.log('Server: Rate Limit Protection - Waiting before trying again.') + setTimeout(() => { + login(); + retryCounter = 0; + }, 30*60*1000); +} function connectToDB() { try {