Any way to fix socket hang up problem?


Here is my package. json

  "name": "Pikachu",
  "version": "1.0.2",
  "description": "A Discord Bot written in Discord.js",
  "engines": {
    "node": "10.x",
    "npm": "4.2.0"
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  "dependencies": {
    "canvas": "^2.0.1",
    "canvas-constructor": "^1.1.2",
    "chalk": "^2.4.1",
    "cheerio": "^0.22.0",
    "dblapi.js": "^2.2.0",
    "discord.js": "github:discordjs/discord.js#",
    "ejs": "^2.6.1",
    "enmap": "3.x",
    "enmap-mongo": "^2.0.2",
    "express": "^4.16.4",
    "fs": "^0.0.2",
    "fs-nextra": "^0.3.7",
    "he": "^1.2.0",
    "idiotic-api": "^0.2.11",
    "moment": "^2.22.2",
    "moment-duration-format": "^2.2.2",
    "prism-media": "^0.3.1",
    "random-puppy": "^1.1.0",
    "request": "^2.88.0",
    "return-deep-diff": "^0.3.0",
    "snekfetch": "^4.0.4",
    "superagent": "^3.8.3",
    "urban-dictionary": "^2.2.1",
    "weather-js": "^2.0.0",
    "wikifakt": "^1.0.3",
    "xml2js": "^0.4.19",
    "node-fetch": "^2.2.0"
  "keywords": [
  "license": "MIT"

MOD EDIT: cleaned up code formatting


Here is the error

    Possibly Unhandled Rejection at: Promise Promise {8:12 AM

<rejected> { Error [WS_CONNECTION_TIMEOUT]: The connection to the gateway timed out.8:12 AM

at Timeout.setTimeout (/rbd/pnpm-volume/5c4f3043-faa8-4f56-8ee3-4da9829839c8/node_modules/ AM

at ontimeout (timers.js:436:11)8:12 AM

at tryOnTimeout (timers.js:300:5)8:12 AM

at unrefdHandle (timers.js:520:7)8:12 AM

at Timer.processTimers (timers.js:222:12) [Symbol(code)]: 'WS_CONNECTION_TIMEOUT' } } reason: { Error [WS_CONNECTION_TIMEOUT]: The connection to the gateway timed out.8:12 AM

at Timeout.setTimeout (/rbd/pnpm-volume/5c4f3043-faa8-4f56-8ee3-4da9829839c8/node_modules/ AM

at ontimeout (timers.js:436:11)8:12 AM

at tryOnTimeout (timers.js:300:5)8:12 AM

at unrefdHandle (timers.js:520:7)8:12 AM

at Timer.processTimers (timers.js:222:12) [Symbol(code)]: 'WS_CONNECTION_TIMEOUT' }8:12 AM

a few seconds ago


Based on a quick review it looks like a built-in discord.js process is trying to connect to some url and is timing out. I’d probably start by verifying every url the discord client tries to connect to and disabling them one by one to see if you can make the error go away.

You could try to narrow it down first by determining which connections the client makes use a timer in their process - not knowing a ton about discord.js I’m not sure if that will actually narrow anything down.


It doesn’t work now :frowning:


@cori can you tell me how you fixed my bot?


Guys, it’s ridiculously simple. You shouldn’t use glitch to host discord bots that are used a lot of times per day. Yes, I host bots here, but simply switching to a real VPS solves this problem. Internet is limited, and thus you stop recieving responses. I had this with my old VPS. A lot. Upgrading the internet solved this problem completely. VPS’s don’t have to be expensive. You can get the same things that glitch has with unmetered internet for $1,66 per month ($20/year).


That doesn’t gonna help me


“simply switching to a real VPS solves this problem.”

Or try making less requests somehow.


Well if i can afford a real vps i never used glitch in first place also second about request then idk what is causing that issue! You’re not really helping in this issue!


What kind of discord bot do you have? Describe very detailed.


That’s really off topic now ! @lieuwe_berg


Hi everyone,

let’s try to keep a meaningful and productive conversation, without blaming at each other. Moreover, yeah, you can always switch to something else, but we’ll do the possible to keep everyone on Glitch, if we can :slight_smile:

@ArunKapil01, I think that @lieuwe_berg question is on the right path to help you with your issue. Socket hangup problems are difficult to track down and resolve, so it’s important to know what your discord bot does, otherwise we can’t help if not with very general suggestions.

Here comes one of the general suggestions :stuck_out_tongue: Try to find the place that generates this issue, and try to catch the exception. Then you can print more detailed information about the request that failed, and you might eventually come to a solution.


That’s what I was aiming for yeah. To add, describe what every command does. If it just sends, or plays music, or posts to hastebin etc.

#54 here is full list of info @lieuwe_berg


And also music and two commands which is on other project works properly only pikachu project not works


I see that it’s in 1774 servers, is that correct?


Yeah i purge many it was working even when it was in 2300 guilds. I purged because i thought that guilds may be the issue but that doesn’t help!


This is more or less what I was talking about but @etamponi said it much better:

One way to isolate where the error comes from is to disable features one at a time and observe things, seeing if the socket timeout stops. If it does then you know what’s causing it and you can either remove that feature or dig deeper to try to solve the problem somehow. But there’s no one-size-fits-all answer - it’s going to be very specific to your bot and is going to take careful, painstaking work that no one else is likely to be able to do for you to find and sort.

And to answer your previous question @ArunKapil01 I didn’t change anything when it started to work earlier, so something changed elsewhere, at least temporarily. That’s another possible line on the problem; what could possibly have changed in that timespan that would affect the bot’s operation without any code change? You could start that line of investigation by listing all the possible things that could have changed there and looking into them one by one.


You don’t have enough traffic availablity for that amount of servers. Socket hang up occurs on discord bots when this issue is present. You probably also don’t have enough ram, but that doesn’t produce this error.

I’m speaking from experience. There’s nothing wrong with your code as the error originates from the package. If it was something in your code, you’d get a different stack error.

Get a VPS, they’re not expensive. I like glitch - I love it -, but it cannot handle such discord bot. Asking for donators or having donator-only commands will help you cover the funds. Patreon works perfectly, but donate bot or simple PayPal donations work fine too.


Thanks for your suggestion but i don’t have a PAN card yet and don’t even have a credit card i am student and i don’t have that even i pay only through cash so i don’t think i can get a vps now or later!
Also my code have issue for sure( I don’t use async for my code i am planning to switch to eris) , as my other project ( music , cleverbot and pokedex commands working properly, They also have a lot of traffic as they have same bot token) and my old friend bot which is in 2400 guilds hosted on glitch works perfectly too!