Hakunek
Hakunek

Reputation: 23

Discord.js Rate Limit Delay

Before you read the question, I would like to inform you that I'm not intrested in command cooldown thing and this question is not connected to it.

Since my friend server got raided about 30 times last week I stared wondering about writing a bot in js using discord.js v12...


But...
I couldn't find a way to get over Discord rate limit. By that I mean so if the action of the bot is rejected bcs of rate limit the bot will wait for those 5 seconds and would go again with the action.

So, let me explain it a little further with an example:
20 raiders started spamming with pings etc. bot detected that but after few bans meets the rate limit, and since we don't want to just spam discord API and keep receiving messages about rate limiting I wonder if we could slow it down a little so the bot would ban 1 pearson from those 20 per second or get info how much do we need to wait after receiving rate limit message and resuming actions after the time we had to wait
Yeah I know that this may be quite slow but at least will work...

Sorry for over complicating this a little ^-^"

Upvotes: 1

Views: 9348

Answers (1)

Tayflo
Tayflo

Reputation: 56

I don't have a turnkey solution for you, but here are some resources to check out that could help you:

Rate limits are dynamic, hence the "rateLimit" event of the library could be of use to you.

However, I had the notion discord.js natively handled rate limits by queuing actions accordingly (see here), so I'm unsure you have to handle this by yourself.

By the way, useful resources if you are a beginner with discord.js: https://discordjs.guide/

PS: You could also step up the verification level of your server. It probably would be both more easy and effective.

Upvotes: 4

Related Questions