#but receiving commands but not responding and not restarting

46 messages · Page 1 of 1 (latest)

timber nymph
#

Hi!
I've got a problem with my bot.
It works fine most of the time and restarts correctly every day.
However, it sometimes stops responding to commands and can no longer send messages.
In the console I can see that commands are received but not answered. There are no errors sent (even with .catch).
I can evaluate javascript code via discord with an eval command which allows me to deduce the following elements:

  • I can access client data such as client.username or client.id, I can console.log and view them.
  • When I make a fetch attempt, for example: (eval client.users.fetch("360034833876910082").then(console.log).catch(console.log)) I get no response, positive or negative.
    When I try to restart the bot, the commands are loaded, it connects to its database but the shard doesn't spawn. Without an error, nothing happens and no shard spawns.
    It's on just over 22k guilds. I wonder if there isn't a ratelimit story behind this, where I might have done something wrong. But not having made any mistakes I don't understand.
    Has anyone encountered a similar problem?
    Thanks in advance!
viral dewBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by staff
timber nymph
#

I just found that I have the same problem with a test bot on the same host

upper scaffold
#

I'm not really sure what is happening, I haven't had anything like this happen before, but I feel like if no error is being thrown, maybe the request is timing out or something? If you do a command, does the bot reply anything at all, even like a Discord generated error like "The application timed out"?

latent maple
upper scaffold
radiant tangleBOT
#

Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.

client
    .on("debug", console.log)
    .on("warn", console.log)
  • Note: if you initialize your Client as bot or other identifiers you need to use these instead of client
  • If the output is too long to post consider using a bin instead: gist | paste.gg | sourceb.in | hastebin
wicked coyote
#

Could be cloudflare ban

timber nymph
timber nymph
wicked coyote
#

You would not get past the „preparing to connect“ log if it was a cloudflare ban

timber nymph
wicked coyote
timber nymph
#

Ouch

wicked coyote
#

Do you run all shards in a single process/rest instance? If not you might hit 429s by two rest instances hitting a ratelimit at the same time. Too many 429s will get you cloudflare banned. Adding a rest proxy might help with that

timber nymph
#

I'm not sure what a 429s is.
I have a dozen shards, running on the same server and the same PM2 process.

radiant tangleBOT
#

discord Rate Limits - Invalid Request Limit aka CloudFlare bans
429 responses are avoided by inspecting the rate limit headers documented above and by not making requests on exhausted buckets until after they have reset. 429 errors returned with X-RateLimit-Scope: shared are not counted against you
read more

timber nymph
#

Hmmm, so it's to much invalid requests ?

wicked coyote
#

Yes

timber nymph
#

I saw I should have 22 shards for 22k guilds, could add shards solve the problem ?

wicked coyote
#

No, it could make the problem worse if anything. You might want to use a rest proxy to keep all your shards using the same ratelimit counters

timber nymph
#

To be honest, I don't know much about it, does Discord JS implement this? Or would there be documentation?

timber nymph
#

Thanks a lot, I will look at this, I have a last question, shouldn't I have received error messages telling me that I was rate-limited?

wicked coyote
#

If you listened to the client.rest.on('rateLimited', ..) and made that log those ratelimits, yes. If you don’t then you won’t. Ratelimits usually aren’t anything to be afraid of, djs will Queue the requests for you until they pass

timber nymph
#

Hmmm, good to know, I'm going to find out all about it, thanks again!

timber nymph
# wicked coyote No, it could make the problem worse if anything. You might want to use a rest pr...

Hello again, after a bit of investigation and your messages I think I've understood the problem. My bot is divided into shards, and the shards independently manage the queue system to avoid ratelimits. So some people send requests when I'm already limited, which leads to a cloudflare ban.
So to avoid this I'd have to "group" the shards (queues) using a rest proxy.
All I know about proxies is that they are intermediaries for communicating between a client and a server, for example.
I've done some research but I can't see how to implement this "grouping". I guess the code in the documentation isn't enough:

import { REST } from '@discordjs/rest';

const rest = new REST({
    api: 'http://localhost:8080/api',
});

but I have no idea what I should add / start developing.
I don't want to take up too much of your time, but maybe you've got a hint or example handy?

wicked coyote
#

And then run the docker image of the proxy-container somewhere (probably on the same server you run your shards on, since you have all shards on the same host, right?)

timber nymph
#

Yep, they are all on the same host

#

I'm gonna learn to use Docker, I think the time has come

#

So, while doing this, I will have a rest instance running in local, something like this ?
Discord API <-> Cloudflare <-> My local rest <-> Shards 0, 1, 2 etc.
Discord API <- Cloudflare <- My local rest <- Shards 0, 1, 2 etc.

#

And it should work

wicked coyote
#

Well, REST is a one-way-street, not a constant connection like the gateway is. But yes, the diagram is about right

timber nymph
#

That's true, thanks

timber nymph
wicked coyote
#

Sure, the docker is just for convenience, but you can check out the proxy package itself and install manually

timber nymph
wicked coyote
#

What do you need an example for? How to start and run the proxy or how to route your requests from the bot to that proxy?

timber nymph
#

Start and run the proxy

#

With the docker command I succeeded locally