Getting Gateway Ratelimited.

My shards are getting interrupted a lot, in last 12 hours I got 291 reconnecting logs and more than double in last 24 hours. Why is that? Is it normal? Cause I got gateway rate limited yesterday because of this. Although I have a GitHub issue stating that reconnections are not rate limited. https://github.com/discord/discord-api-docs/issues/1369 I am extremely confused as how this (rate-limited) could happen? The bot was not rebooted for few days before we got rate-limited.
34 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Ashu
AshuOP2y ago
npm list discord.js
Ashu
AshuOP2y ago
node -v
Ashu
AshuOP2y ago
While i noticed Resume event falls under Send Events which is also a part of 120 send events per connection per 60 seconds. https://discord.com/developers/docs/topics/gateway#rate-limiting https://discord.com/developers/docs/topics/gateway-events
Ashu
AshuOP2y ago
+1 How do I know if they are identity or resumes? resume event doesn't give me any info The machine got blocked again today. @qjuh
HTTP/2 429date: Sat, 08 Jul 2023 04:25:51 GMT
content-type: text/plain; charset=UTF-8content-length: 16
retry-after: 35671x-frame-options: SAMEORIGIN
referrer-policy: same-origin
cache-control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
expires: Thu, 01 Jan 1970 00:00:01 GMT
report-to: {"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v3?s=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}],"group":"cf-nel","max_age":604800}nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
content-security-policy: frame-ancestors 'none'; default-src 'none'
server: cloudflare
cf-ray: XXXXXXXXXXXXXXXXXXXXXX
alt-svc: h3=":443"; ma=86400
HTTP/2 429date: Sat, 08 Jul 2023 04:25:51 GMT
content-type: text/plain; charset=UTF-8content-length: 16
retry-after: 35671x-frame-options: SAMEORIGIN
referrer-policy: same-origin
cache-control: private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
expires: Thu, 01 Jan 1970 00:00:01 GMT
report-to: {"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v3?s=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"}],"group":"cf-nel","max_age":604800}nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
strict-transport-security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
content-security-policy: frame-ancestors 'none'; default-src 'none'
server: cloudflare
cf-ray: XXXXXXXXXXXXXXXXXXXXXX
alt-svc: h3=":443"; ma=86400
I got this when I try to curl the gateway endpoint and use -i flag to show headers Does this mean its a cloudflare ratelimit and not discord? Or this is just how Discord blocks our requests? Using Cloudflare? Hmm, I was inspecting logs and I see a tons of Unknown Interaction and Already Defered Error. Would that be a problem? Unknown Interaction is 404 ig So 401 errors will be Invalid Webhook Tokens right? 403 is for channel and role permission. So I gotta check the permissions before sending. How do I check that cause, its really random sometimes. Is deferred reliable? Hmm okay I will check that now Thanks for the help @qjuh Hey why are my shards are being closed with 4200 code?
Ashu
AshuOP2y ago
What does code 4200 mean?
Ashu
AshuOP2y ago
Okay, so it fine right no issues? Ah Thanks :)
Ashu
AshuOP2y ago
Why the bot has spicks of huge invalid webhook token? This is a monthly graph 7k+ logs
Ashu
AshuOP2y ago
It can't be the code, how could it produce spikes like these lol hmm how do I montior that? cause that weird No I mean, how can I montior the load Like what is causing it Cause the machine is very powerful and it has the Bot and Mongodb server running that's all I am not monitoring that. I didn't know how to do that tbh using Grafana I don't think it has other monitoring in place rn hmm okay let me do that Already deferred is 400 error, is that also a problem? Cause I am checking for Interaction#defered but someone some interactions are still throwing that error. So I am assuming that that field is not very dependable or not accurate all the time?
Ashu
AshuOP2y ago
Green Arrow: I am checking the defered field Red Arrow: Getting those errors
Ashu
AshuOP2y ago
Bump I last 24 hours I got 131 Interaction has already been acknowledged errors @qjuh Now I don't have 2 instances of bots and Yes I am using collector and most of the Unknown interaction errors are happening in that collector. I don't think 2 collectors are as I have collector attached to the message itself and it checks for member id to make sure onlt that member replies to the message.
d.js docs
d.js docs2y ago
Common causes of DiscordAPIError[10062]: Unknown interaction: - Initial response took more than 3 seconds ➞ defer the response *. - Wrong interaction object inside a collector. * Note: you cannot defer modal or autocomplete value responses
Ashu
AshuOP2y ago
What does Wrong interaction object inside a collector. mean? How could that happening? Cause I get like 300 Unknown interaction every hour. I do check them for 3 seconds time frame and I instantly defer or reply to them. Checked my code no issues found. But still somehow I get these unknown interaction errors. Most of the interactions success but some just get failed with this error. I also noticed most of them that are failing are using a colletor. There are 0 reports of the feature that is causing this error not working or working incorrectly. So I am not sure
Ashu
AshuOP2y ago
This i mean
Ashu
AshuOP2y ago
Link Removed Here
/**
* @type {Message<boolean>}
*/
let reply;
if (interaction.deferred) {
reply = await interaction.editReply({
content: humanVerificationPart1.content,
embeds: [
humanVerificationPart1.embeds[0],
humanVerificationPart2.embeds[0],
],
components: part2Buttons,
files: [attachment],
});
} else {
reply = await interaction.reply({
content: humanVerificationPart1.content,
embeds: [
humanVerificationPart1.embeds[0],
humanVerificationPart2.embeds[0],
],
components: part2Buttons,
files: [attachment],
ephemeral: true,
fetchReply: true,
});
}
const { enteredCaptcha, timedOut, component } =
await numberCaptchaWithNumpad(interaction, reply, captchaText);
/**
* @type {Message<boolean>}
*/
let reply;
if (interaction.deferred) {
reply = await interaction.editReply({
content: humanVerificationPart1.content,
embeds: [
humanVerificationPart1.embeds[0],
humanVerificationPart2.embeds[0],
],
components: part2Buttons,
files: [attachment],
});
} else {
reply = await interaction.reply({
content: humanVerificationPart1.content,
embeds: [
humanVerificationPart1.embeds[0],
humanVerificationPart2.embeds[0],
],
components: part2Buttons,
files: [attachment],
ephemeral: true,
fetchReply: true,
});
}
const { enteredCaptcha, timedOut, component } =
await numberCaptchaWithNumpad(interaction, reply, captchaText);
99% of the errors happen on updateCaptchaMessage function call. Just above ya Everything is fine to this point No errors or issues. Its also not like I am trying to update or using the main interaction, I am using the i variable that is button interaction in the collector. Here is the full function: Link Remove and that function just gets called in a button interaction create event Essentially that's verification the whole code It depends on the function that calls the provided function, it could be non-defered and it could be defered thats why I have that defer check. No I don't have that button and Yes I am using deferUpdates, Can I send you all the functions calling that function in DM? The whole file But I close the collector on submit button and when they click verify button, it makes a new message everytime Collector times out If they click verify twice or more, there will be multiple messages with difference collectors . Shall I send you the whole file in DM?
Ashu
AshuOP2y ago
Ashu
AshuOP2y ago
It always a new message when they click verify button I tried clicking verify twice and more and it throws no errors If you are worried about virus or something, I could just send you a pastebin Okay gimme a min Sent Yes, I just did that actually. Still have to push that update in the live version. I will send you as soon as I push and get those logged. What I feel so far is it could be either the code is talking more than 3 seconds to reach the update function or Discord API just lagging. I have seen Discord API lagging before but still not sure. But that for Unknown Interaction Yes No idea about the acknowledged errors
d.js docs
d.js docs2y ago
- DiscordAPIError: Interaction has already been acknowledged - [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred. You have already replied to the interaction. - Use <Interaction>.followUp() to send a new message - If you deferred reply it's better to use <Interaction>.editReply() - Responding to slash commands / buttons / select menus
Ashu
AshuOP2y ago
Yeah, I know how it works Okay Interaction has already been acknowledged I didn't quite get that 99% of them Hmmmmmm The main problem is no one has reported any issues with the numpad, I am not able to reproduce the issue I don't think I ever coded anything like this, casue that would be a dead giveaway of the reason Hmm okay Hmm okay I did that as well lets see
error: [14/07/2023 04:53:04] [ERROR] [24803] [req8o8vzWt] [Cluster 0] [Shard 2] [INTERNAL ONLY] [XXXXXXXXX] Failed to update message for XXXXXXXXXXXXXXXX for number captcha with numpad. Debug Data: Method Called At: Fri Jul 14 2023 04:53:03 GMT+0000 (Coordinated Universal Time) (1689310383186) | Replied At: Fri Jul 14 2023 04:53:03 GMT+0000 (Coordinated Universal Time) (1689310383187) | Interaction Created At: Fri Jul 14 2023 04:53:03 GMT+0000 (Coordinated Universal Time) (1689310383132) | Errored At: Fri Jul 14 2023 04:53:03 GMT+0000 (Coordinated Universal Time) (1689310383302) | Event Counts: 7 | Error: DiscordAPIError[10062]: Unknown interaction
Stack: DiscordAPIError[10062]: Unknown interaction
error: [14/07/2023 04:53:04] [ERROR] [24803] [req8o8vzWt] [Cluster 0] [Shard 2] [INTERNAL ONLY] [XXXXXXXXX] Failed to update message for XXXXXXXXXXXXXXXX for number captcha with numpad. Debug Data: Method Called At: Fri Jul 14 2023 04:53:03 GMT+0000 (Coordinated Universal Time) (1689310383186) | Replied At: Fri Jul 14 2023 04:53:03 GMT+0000 (Coordinated Universal Time) (1689310383187) | Interaction Created At: Fri Jul 14 2023 04:53:03 GMT+0000 (Coordinated Universal Time) (1689310383132) | Errored At: Fri Jul 14 2023 04:53:03 GMT+0000 (Coordinated Universal Time) (1689310383302) | Event Counts: 7 | Error: DiscordAPIError[10062]: Unknown interaction
Stack: DiscordAPIError[10062]: Unknown interaction
What the heck? Who could it say unknown interaction in just few milliseconds? Interaction Created At - Errored At = 170ms All of the 100s of errors are the same kind Also, about the Interaction has already been acknowledged error. Is there any way I can get the number of collectors on a message?
error: [14/07/2023 04:22:29] [ERROR] [25213] [NG0YR3JIrT] [Cluster 11] [Shard 45] [INTERNAL ONLY] [XXXXXXXXXX] Failed to update message for XXXXXXXXXXXXXXXXX for number captcha with numpad. Debug Data: Method Called At: Fri Jul 14 2023 04:22:28 GMT+0000 (Coordinated Universal Time) (1689308548760) | Replied At: Fri Jul 14 2023 04:22:28 GMT+0000 (Coordinated Universal Time) (1689308548761) | Interaction Created At: Fri Jul 14 2023 04:22:28 GMT+0000 (Coordinated Universal Time) (1689308548697) | Errored At: Fri Jul 14 2023 04:22:28 GMT+0000 (Coordinated Universal Time) (1689308548923) | Event Counts: 10 | Error: DiscordAPIError[40060]: Interaction has already been acknowledged.
Stack: DiscordAPIError[40060]: Interaction has already been acknowledged.
error: [14/07/2023 04:22:29] [ERROR] [25213] [NG0YR3JIrT] [Cluster 11] [Shard 45] [INTERNAL ONLY] [XXXXXXXXXX] Failed to update message for XXXXXXXXXXXXXXXXX for number captcha with numpad. Debug Data: Method Called At: Fri Jul 14 2023 04:22:28 GMT+0000 (Coordinated Universal Time) (1689308548760) | Replied At: Fri Jul 14 2023 04:22:28 GMT+0000 (Coordinated Universal Time) (1689308548761) | Interaction Created At: Fri Jul 14 2023 04:22:28 GMT+0000 (Coordinated Universal Time) (1689308548697) | Errored At: Fri Jul 14 2023 04:22:28 GMT+0000 (Coordinated Universal Time) (1689308548923) | Event Counts: 10 | Error: DiscordAPIError[40060]: Interaction has already been acknowledged.
Stack: DiscordAPIError[40060]: Interaction has already been acknowledged.
Here is that error There are way many different event listeners on the whole bot...so Event Counts: is really just unreliable. Yeah, right thats for Interaction has already been acknowledged What about the Unknown Interaction tho? How could this ever happen? hmm okay let me build a cache system than Hey, @qjuh So about this issue, I did debugging and found that somehow people where able to press readRulesContinue button twice and it was adding 2 collectors to the same message. So I checked the code and it was defering the button click and than using editReply it was editing the message to the numpad captcha message. So I though its because I when I defer it the button gets active again for the user to be able to click and as I was using a event listener instead of using a one time collector like awaitMessageComponent. So I though If I just use the update function to instantly send the numpad captcha message. I could make it so the button will never have the time to get ready again (ready to be clicked). I did that and I was not able to reproduce this issue ever again. But somehow people are still able to click on the readRulesContinue twice and I am getting 2 collectors on the same message.
Ashu
AshuOP2y ago
Ashu
AshuOP2y ago
I could just check if a message already has a collector in place and it will ignore the second interaction but why this wouldn't work? And I don't wanna add like hacks to the code tbh max:1 for what tho? I am not using awaitMessageComponent You could check the code I sent in DM
Ashu
AshuOP2y ago
Yes but I am not using that method because if the bot gets restarted anytime and a user is in middle of the verification flow, they will have to restart because that button won't work. I am listening to pure interactionCreate event
Ashu
AshuOP2y ago
So users can start on any step regardless if the bot got restarted or not
chewie
chewie2y ago
I know this is off topic, but please for the love of god make a proper button handler
Ashu
AshuOP2y ago
I better managed the verification flow
Ashu
AshuOP2y ago
Oh, any example like what do you mean?
chewie
chewie2y ago
like command handler - just with components to avoid big chunky if else blocks
Ashu
AshuOP2y ago
Yeah, I build a interactionEvent handler in the rewrite. Its all divided now. ^
chewie
chewie2y ago
so thats an old pic or?
Ashu
AshuOP2y ago
So it doesn't just manage buttons, It manages all the interactionCreate types. Yes I rewrote the code.
chewie
chewie2y ago
ah gotcha, reallyFckingPoof
Ashu
AshuOP2y ago
This is the handler if you wanna check if I could improve anything @thehairy https://pastebin.com/PX6h8xRM
Pastebin
const { InteractionType } = require('discord.js');const Event = req...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Ashu
AshuOP2y ago
Yeah, I mean the way rn I log that how many collectors a message has, I could just check the amount of collectors on a message and cancel the button click process right away but I am very curious that why do I have to implement a hack. How is discord allowing user to be able to click a button twice even tho I can sending an update reply? The button should just keep processing and replace with new message. Isn't it? Oh, so is that from our side or could be Discord as well? No I meant the network traffic. Is it our network being slow or is it Discord talking time. I don't understand just a simple thing. The button should not be active (clickable by a user) for 3 seconds till my bot has replied. It should I be active if I defer the update within 3 seconds time frame. Ahh okay, and the second part any idea? ;__; hmmmmmmmmmmmmmmmmmmmm okay I will add that check than btw does this look good? and also Thanks for all the time and help. Love ya :)
error: [17/07/2023 18:27:13] [ERROR] [11041] [Uw410xaZKN] [Shard 11] [INTERNAL ONLY] [XXXXXXXXXX] [XXXXXXXX] Failed to update message for XXXXXXXXXXX (XXXXXXXXXXXXX) for number captcha with numpad. Debug Data: Method Called At: Mon Jul 17 2023 18:26:56 GMT+0000 (Coordinated Universal Time) (1689618416986) | Replied At: Mon Jul 17 2023 18:26:56 GMT+0000 (Coordinated Universal Time) (1689618416986) | Interaction Created At: Mon Jul 17 2023 18:26:56 GMT+0000 (Coordinated Universal Time) (1689618416919) | Errored At: Mon Jul 17 2023 18:27:12 GMT+0000 (Coordinated Universal Time) (1689618432155) | Event Counts: 4 | Collectors: 0 | Replied: false | Error: DiscordAPIError[10062]: Unknown interaction
error: [17/07/2023 18:27:13] [ERROR] [11041] [Uw410xaZKN] [Shard 11] [INTERNAL ONLY] [XXXXXXXXXX] [XXXXXXXX] Failed to update message for XXXXXXXXXXX (XXXXXXXXXXXXX) for number captcha with numpad. Debug Data: Method Called At: Mon Jul 17 2023 18:26:56 GMT+0000 (Coordinated Universal Time) (1689618416986) | Replied At: Mon Jul 17 2023 18:26:56 GMT+0000 (Coordinated Universal Time) (1689618416986) | Interaction Created At: Mon Jul 17 2023 18:26:56 GMT+0000 (Coordinated Universal Time) (1689618416919) | Errored At: Mon Jul 17 2023 18:27:12 GMT+0000 (Coordinated Universal Time) (1689618432155) | Event Counts: 4 | Collectors: 0 | Replied: false | Error: DiscordAPIError[10062]: Unknown interaction
An example how Discord also lags sometimes Interaction Created At - Replied At = 67ms Replied At - Errored At = 15169ms Btw need an advice, if I found an existing collector. Should I let the existing collector do the job or should I stop the old collectors and continue the code to send the update with the numpad captcha message and make new collector? @qjuh Oh, I am really sorry. I will remember. Hmm okay Thanks
Want results from more Discord servers?
Add your server