#Getting Gateway Ratelimited.

208 messages · Page 1 of 1 (latest)

chrome adder
#

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.

strong folioBOT
#

• 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.

chrome adder
#

npm list discord.js

#

node -v

chrome adder
#

+1

keen iron
#

Listen to the resume event to find out if they are resumes or full reconnects with identity. Resumes are normal and perfectly fine

chrome adder
#

How do I know if they are identity or resumes?

#

resume event doesn't give me any info

#

The machine got blocked again today. @keen iron

chrome adder
#
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?

chrome adder
#

Or this is just how Discord blocks our requests? Using Cloudflare?

keen iron
#

Discord use cloudflare, yes. But if you get a cf 429 that means you sent too many invalid requests in a shortish amount of time (causing 401 or 403 especially)

chrome adder
#

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.

keen iron
#

Already deferred is a problem. Unknown interaction doesn’t get you cf rateLimited

chrome adder
#

How do I check that cause, its really random sometimes. Is deferred reliable?

keen iron
#

It shouldn’t be random. You need to make sure you only handle each interaction in one place only. If you get a already deferred error the next time look at the stacktrace (and make sure to await all your deferReply and deferUpdate to get a meaningful stacktrace)

chrome adder
#

Hmm okay I will check that now

#

Thanks for the help

chrome adder
#

@keen iron Hey why are my shards are being closed with 4200 code?

#

What does code 4200 mean?

keen iron
#

Resuming

#

And it should emit with reason: too in current/recent version

chrome adder
#

Okay, so it fine right no issues?

keen iron
#

Yes, probably just discord asking to reconnect as it does once in a while. Resumes are perfectly fine and harmless

chrome adder
#

Ah Thanks :)

chrome adder
#

Why the bot has spicks of huge invalid webhook token?
This is a monthly graph 7k+ logs

#

It can't be the code, how could it produce spikes like these lol

keen iron
#

If something slows your bot‘s server or process down it‘ll suddenly reply to all interaction‘s too late. So could be load

chrome adder
#

hmm

#

how do I montior that?

#

cause that weird

keen iron
#

Well, 7k interactions in such a short time already seems like you‘re monitoring it

chrome adder
#

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

keen iron
#

Any memory/cpu spikes?

chrome adder
#

I am not monitoring that. I didn't know how to do that tbh

keen iron
#

Then how are you monitoring the logs there?

chrome adder
#

using Grafana

#

I don't think it has other monitoring in place rn

keen iron
#

Add prometheus node exporter to grafana then

#

(Not related to NodeJS)

chrome adder
#

hmm

#

okay

#

let me do that

chrome adder
#

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?

#

Green Arrow: I am checking the defered field
Red Arrow: Getting those errors

chrome adder
#

Bump

#

I last 24 hours I got 131 Interaction has already been acknowledged errors

#

@keen iron

keen iron
#

And from where? Do you have collectors that can possibly run in parallel and both try to reply? Or do you have two instances of your bot running somewhere?

chrome adder
#

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.

cursive furnaceBOT
#

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
chrome adder
#

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

keen iron
chrome adder
#

This i mean

keen iron
#

And where do you call that function?

#

Please put the relevant code in a pastebin. Screenshots are hard to work with

chrome adder
#

Link Removed

#

Here

keen iron
#

Where do you call that function? I need to see what you pass as parameters to it (if you call it from multiple places I need all of them)

chrome adder
#
      /**
       * @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.

keen iron
#

Ah, see it now

chrome adder
#

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.

keen iron
#

But… you editReply there, so both your definitions refer to the same Message anyway. Please show the code before too

keen iron
keen iron
chrome adder
#

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

keen iron
chrome adder
#

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.

keen iron
#

I’m not asking about any defer. I’m asking about deferUpdate specifically. Do you have a can‘t read that, please generate new captcha button for example? Because if you do you probably make a second collector on the same message that way

chrome adder
#

and Yes I am using deferUpdates,

#

Can I send you all the functions calling that function in DM?

#

The whole file

keen iron
chrome adder
#

But I close the collector on submit button

keen iron
#

But what if they don’t push submit button?

chrome adder
#

and when they click verify button, it makes a new message everytime

chrome adder
#

If they click verify twice or more, there will be multiple messages

#

with difference collectors

keen iron
#

But what if you start the new collector before time runs out and then they push submit button?

keen iron
chrome adder
#

Shall I send you the whole file in DM?

keen iron
#

No. Send me screenshots of the messages sent in discord these collectors are running on.

chrome adder
#

It always a new message when they click verify button

#

I tried clicking verify twice and more and it throws no errors

chrome adder
keen iron
chrome adder
#

Okay gimme a min

#

Sent

keen iron
#

I see you got rather excessive logging for that error case there, mind sharing one of those errors including stack? You can redact the member in the log ofc

chrome adder
#

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.

keen iron
#

But that wouldn’t cause already acknowledged errors…

chrome adder
#

But that for Unknown Interaction

#

Yes

#

No idea about the acknowledged errors

cursive furnaceBOT
#
  • 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
chrome adder
#

Yeah, I know how it works

keen iron
#

Not helpful for your case I guess… just wanted to take a look what out tag says

chrome adder
#

Okay

keen iron
chrome adder
#

Interaction has already been acknowledged

keen iron
#

Then it’s two async tasks both responding. Not two responses in the same awaited chain

#

You await all your interaction responses (and their containing functions), right?

chrome adder
#

I didn't quite get that

#

99% of them

keen iron
#
await interaction.deferUpdate();
await interaction.update();

won‘t send the error you get,

interaction.deferUpdate();
await interaction.update();

would though

chrome adder
#

Hmmmmmm

#

The main problem is no one has reported any issues with the numpad, I am not able to reproduce the issue

keen iron
#

Well, you got quite a lot the last time, so it’s wait and see

chrome adder
keen iron
# chrome adder I don't think I ever coded anything like this, casue that would be a dead giveaw...

Well, it won’t be directly one after the other like here… it could be in different functions of yours that are called in the same chain at one point. But the more likely reason is two collectors listening on the same message. If you want to know for certain you could log the messageId you create a collector on everytime you call your function. Would make quite a log file I figure though…

#

Or inside your catch you could at least log client.listenerCount('interactionCreate') to know how many collectors are running at that moment

chrome adder
#

Hmm okay

#

I did that as well

#

lets see

chrome adder
#
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.
```Here is that error
#

There are way many different event listeners on the whole bot...so Event Counts: is really just unreliable.

keen iron
chrome adder
#

Yeah, right thats for Interaction has already been acknowledged

chrome adder
keen iron
chrome adder
#

hmm okay let me build a cache system than

chrome adder
#

Hey, @keen iron 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.

#

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

keen iron
#

Yes. Why don’t you use max:1 btw? Users will always be able to click faster than your reply arrives… (admittedly I forgot what your actual issue was about exactly because I got lots of support cases)

chrome adder
#

max:1 for what tho?

#

I am not using awaitMessageComponent

#

You could check the code I sent in DM

keen iron
#

The collector for the readRulesContinue you said shouldn’t be usable twice

#

max:1 also works for regular collectors, not only promisified ones

#

And I don’t have much motivation to read through all of your code again when you should know better than me where you use what kind of collector

chrome adder
#

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

#

So users can start on any step regardless if the bot got restarted or not

frosty obsidian
#

I know this is off topic, but please for the love of god make a proper button handler

chrome adder
#

I better managed the verification flow

chrome adder
frosty obsidian
#

like command handler - just with components

#

to avoid big chunky if else blocks

chrome adder
#

Yeah, I build a interactionEvent handler in the rewrite.

#

Its all divided now.

chrome adder
frosty obsidian
chrome adder
#

So it doesn't just manage buttons, It manages all the interactionCreate types.

chrome adder
frosty obsidian
#

ah gotcha, nice

chrome adder
keen iron
#

You could store userIds that already clicked the button in a set/collection/array though to stop them from clicking twice (and can have that expire after a short amount of time or even directly after the update to disable/remove the button resolved)

chrome adder
keen iron
chrome adder
#

The button should just keep processing and replace with new message. Isn't it?

chrome adder
keen iron
#

What? The button being clickable several times by the same user is discord. The you trying to reply several times and making several collectors because of that is you not discord

chrome adder
#

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.

keen iron
#

I didn’t say anything about being slow. But even fast network traffic still needs time

chrome adder
#

Ahh okay, and the second part any idea?

keen iron
#

should doesn’t imply is

chrome adder
#

;__;

keen iron
#

Don’t rely on buttons only being usable once every 3s

chrome adder
#

hmmmmmmmmmmmmmmmmmmmm

#

okay

#

I will add that check than

chrome adder
#

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
```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? @keen iron

keen iron
#

You should stop pinging me… will only discourage other people from helping (and me too)

chrome adder
#

Oh, I am really sorry. I will remember.

keen iron
chrome adder
#

Hmm

#

okay