My discord.js bot is having ping up to 2k
How are you pinging your bot?
Well my bot takes forever to respond, takes up to 7 seconds
Ok, that’s not the same thing. As a first step I suggest adding logging to your app when a request is received and a response is sent so you can work out where time is being spent.
It goes to glitch fast but it isnt process fast. How can i make it go faster?
i also get sent “Your app is taking a while to stop…”
And im getting the error " Error: Unhandled “error” event. ([object Object])" I have dmed you a link to my project @Gareth
If your bot uses a third party API, like Discord, then your bot will not be able to respond faster than the amount of time that service needs to get back to your app.
In this case, Discord’s response time appears to be the source of your bot’s delay.
Currently, the Discord’s API Response Time looks a bit better than you initially posted, but it’s definitely something that contributes, significantly, to the delay of your bot’s response.
If you have other 3rd party APIs on your bot, you will need to take their total response time(s) into your calculations, too.
The only occurrence I could see of an unhandled error event in your project is UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 8): DiscordAPIError: Missing Permissions
. Make sure your bot has sufficient permissions to undertake the desired action. See https://discordapp.com/developers/docs/topics/permissions for more info.
hmmm not really sure why people are replying with that it could
be due to missing permissions as it looks completely out of place.
The guy says that his response take up to 7 seconds, meaning he gets a response.
So we can conclude this has not to due with permissions.
If that was the case he would not receive any response back.
High pings in discord can be due to a few factors.
- Discords API is experiencing some troubles.
- You have to much code in a single file that goes waaay to deep.
- you are not using your code correctly.
If discord is having API problems there is nothing you can do
then waiting until this corrects itself again.
If you code everything into a single file without using
imports and exports you can slow everything down.
Javascript reads the information in the file from top to bottum
and if you have a lot of code this will slow everything down.
Try to use module.exports and separate your code.
It could also be you not coding your bot sufficient enough.
Same as going to deep into 1 script this can be slow everything down.
For example.
`If (some value) {
// Some of your code.
}
if (some other value) { // Some of your other code }
Is what a lot of people do but i also terrible.
What happens is your bot will read ALL statements one
by one to check if the value is correct. Once it finds
the right statement its runs that.
Meaning every time someone is using your bot,
your client will go through all of your code to find the correct matching value.
instead use.
if (some value) { // Some code } else if (some other value) { // some other code }
This will speed up the process.
BUT depending on how many servers you are on
this also can be slowed down with extensive use.
My advice would be to split up your code into seperate files.
Then simply once a statement matches your value you re-direct
your client to go to import the information of the needed file.
In the mean time your client is doing that is continues the rest
of your main files code without stepping on the breaks.
A good way of doing it also if to put your code into functions.
if (value == true) return core(); function core () { // Some of your code }
Make sure you use the return statement
if you want to script to stop after going to the function.
Initially you can call a now function within the function to continue.
`if (value == true) return core();
function core () {
// Some of your code
return otherFunction()
}
function otherFunction() {
// Do some other code
}`
Also this will make sure not all of your
get read every single time speeding up the process.
Also very important to note is async / await
.
If you would a lot with databases and or code that needs to
pause for a moment until it fetches all the info.
This will round house kick to the face for your code
Using this to much in a single file slows your bot down like hell.
Best is to use this within a function or importing it from a different file
so your main code can continue.
The last issues that can cause this are incorrect port forwarding in your router…
The bot default connection is via port 443 and this port is also used for
countless of other of your PC services. If the port gets overloaded it either
puts you on hold or simply crashes. This result in a timeout error.
But it absolutly has nothing to do with your Discord permissions.
If this was the case you would not receive any result at all and you
would get an Missing Permissions
error in your console.
If you get any errors but you do not get enough info to debunk
you can use --trace-warnings
. This will show you a more detailed
information where the error was generated.
I hope it helps and god speed my friend !!
No-one suggested the high ping was due to a permissions issue. The poster said they were also seeing an unhandled error (I am experiencing high ping) and when I looked into the project the cause of the error was a permissions issue (I am experiencing high ping).