# Bot Disconnecting

**URL:** <https://staging-discuss.dev.twitch.com/t/bot-disconnecting/8278>\
**Category:** Chat and IRC\
**Created:** [November 29, 2016, 1:28pm UTC](https://staging-discuss.dev.twitch.com/t/bot-disconnecting/8278 "2016-11-29T13:28:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Z.Ibrahimovic](https://avatars.discourse-cdn.com/v4/letter/z/7ba0ec/32.png) [@Z.Ibrahimovic](https://staging-discuss.dev.twitch.com/u/Z.Ibrahimovic)\
**Post date:** [November 29, 2016, 1:28pm UTC](https://staging-discuss.dev.twitch.com/t/bot-disconnecting/8278/1 "2016-11-29T13:28:01Z")

</div>

I am using Phantombot and already contacted their support forums and Discord.  
[https://community.phantombot.tv/topic/734/bot-stop-working-from-time-to-time/79](https://community.phantombot.tv/topic/734/bot-stop-working-from-time-to-time/79)

The disconnect symptoms:  
When turning the bot on and the stream is offline, the bot disappears in 5 or 10 minutes from the chat. When the stream is live and the twitchchat is active, the bot just keeps going like a champ. After a 6 hours stream the bot can be for many more hours in the chat with a dead chat. Eventually during the night it somewhere disconnects from chat. The console does not state anything special, nor do the logs.

The bot does not freeze or anything; the discord feature and the controlpanel keep running when the bot is disconnected from twitchchat. The bot does not reconnect by itself which it should. It requires a manual reconnect by console command to get it back into the chat. Rebooting the bot makes it instantly function again as well, so it looks not to be a temp ban.

Some say I need to request the bot to be whitelisted. Some say it has something to do with connecting from Germany/ The Netherlands where others have had issues lately as well for connecting overseas to twitchchat with a bot.

What can cause the issue? What can solve it? Any help is appreciated 🙂

A log from when a disconnect occurs since last ping-pong. Only the last two lines are repeated, the ping-pong does not occur anymore after the disconnect:

[11-27-2016 @ 17:35:22.361 GMT] Got a ping from Twitch: PING :tmi.twitch.tv.

[11-27-2016 @ 17:35:22.361 GMT] Sent a pong to Twitch.

[11-27-2016 @ 17:35:27.572 GMT] TwitchCache::updateCache

[11-27-2016 @ 17:35:50.580 GMT] ChannelHostCache: Success with TMI

[11-27-2016 @ 17:35:58.338 GMT] TwitchCache::updateCache

[11-27-2016 @ 17:36:08.378 GMT] Dispatched event me.mast3rplan.phantombot.event.discord.DiscordEvent

[11-27-2016 @ 17:36:10.742 GMT] Dispatched event me.mast3rplan.phantombot.event.discord.DiscordEvent

[11-27-2016 @ 17:36:21.259 GMT] ChannelHostCache: Success with TMI

[11-27-2016 @ 17:36:29.238 GMT] TwitchCache::updateCache

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [November 29, 2016, 1:49pm UTC](https://staging-discuss.dev.twitch.com/t/bot-disconnecting/8278/2 "2016-11-29T13:49:52Z")

</div>

We’d have to defer you back to the dev of the bot.

They would have to debug and fix the issue.  
Seems the problem is with the bot itself since: [quote=“Z.Ibrahimovic, post:1, topic:8278”]  
The bot does not reconnect by itself which it should  
[/quote]

---

<div class="post-metadata">

**Author:** ![IllusionaryOne](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/illusionaryone/32/2011_2.png) [@IllusionaryOne](https://staging-discuss.dev.twitch.com/u/IllusionaryOne)\
**Post date:** [November 29, 2016, 5:59pm UTC](https://staging-discuss.dev.twitch.com/t/bot-disconnecting/8278/3 "2016-11-29T17:59:44Z")

</div>

Bot Developer here. I agree, but, I seem to recall in the past that there have been some connectivity issues from the EU (Germany, etc) to the WS-IRC servers in the AWS in Oregon - am I remembering that correctly at least? I am looking into the 3rd party library that provides the WebSocket connectivity, but, if there is never a PING from Twitch and the library does not recognize a disconnect (it does from my house at least, when I have lost internet or unplugged the ethernet cable) - it would seem to me that something else is going on. From what I recall in network engineering (I spent 12+ years at Verizon and CenturyLink on the enterprise network side developing software), the TCP connection may not disconnect but may stop sending data - so perhaps, what I should consider is, if I do not see a PING from Twitch that the connection is no longer properly sending data.

---

<div class="post-metadata">

**Author:** ![3ventic](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/3ventic/32/298_2.png) [@3ventic](https://staging-discuss.dev.twitch.com/u/3ventic)\
**Post date:** [November 29, 2016, 6:11pm UTC](https://staging-discuss.dev.twitch.com/t/bot-disconnecting/8278/4 "2016-11-29T18:11:38Z")

</div>

The bot should be sending its own `PING`s to check that the connection is still alive.

---

<div class="post-metadata">

**Author:** ![IllusionaryOne](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/illusionaryone/32/2011_2.png) [@IllusionaryOne](https://staging-discuss.dev.twitch.com/u/IllusionaryOne)\
**Post date:** [November 29, 2016, 6:13pm UTC](https://staging-discuss.dev.twitch.com/t/bot-disconnecting/8278/5 "2016-11-29T18:13:26Z")

</div>

Apologies, have that backwards and did not have the API documentation or code in front of me at the time. I of course meant PONG.

[EDIT] Actually…

About once every five minutes, you will receive a PING :tmi.twitch.tv from the server, in order to ensure that your connection to the server is not prematurely terminated, you should reply with PONG :tmi.twitch.tv.

Are the IRC API docs wrong? I should expect a PING every ~5 minutes?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://staging-discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [November 29, 2016, 6:47pm UTC](https://staging-discuss.dev.twitch.com/t/bot-disconnecting/8278/6 "2016-11-29T18:47:03Z")

</div>

My code if it doesn’t get a PING/other message in a timely it’ll send it’s own PING and if no PONG do the restart loop.

Either way, it’s possible for a bot to miss a server ping, which is why if you don’t have a sever ping in a timely fashion you send your own to test if it was a missed ping, or you connection dropped/terminated/whatever.

Twitch docs states:

> About once every five minutes, you will receive a PING :tmi.twitch.tv from the server, in order to ensure that your connection to the server is not prematurely terminated, you should reply with PONG :tmi.twitch.tv.

Source: [Chat & Chatbots | Twitch Developers](https://dev.twitch.tv/docs/irc/)

Interestingly RFC 1459 says that servers don’t have to respond to client initiated PING’s but I’m sure they all do:

> Any client which receives a PING message must respond to   
> (server which sent the PING message out) as quickly as possible with  
> an appropriate PONG message to indicate it is still there and alive.  
> Servers should not respond to PING commands but rely on PINGs from  
> the other end of the connection to indicate the connection is alive.  
> If the parameter is specified, the PING message gets  
> forwarded there.

NodeIRC itself uses a cycling ping timer and sends a PING to the Server if it’s not had one for a while. Which is the logical thing to do.

> <https://github.com/martynsmith/node-irc/blob/master/lib/cycling_ping_timer.js>

That said, if a bot hasn’t had a server initiated ping, or ANY packer of data, then yeah it’s supposed to reconnect/deal with it how ever it wants.

So to take this topic back on track. It’s a problem with the bot not realising it may have disconnected from Twitch chat, and dealing with that accordingly

---

<div class="post-metadata">

**Author:** ![IllusionaryOne](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/illusionaryone/32/2011_2.png) [@IllusionaryOne](https://staging-discuss.dev.twitch.com/u/IllusionaryOne)\
**Post date:** [November 29, 2016, 7:18pm UTC](https://staging-discuss.dev.twitch.com/t/bot-disconnecting/8278/7 "2016-11-29T19:18:44Z")

</div>

Barry - thanks for the extra information, like I said, I agreed it was the bot, I have already coded in a timer subsystem to expect back replies from Twitch now and if not, it forces a reconnect in the meantime in hopes that resolves the issue for the user.

Thanks again!

---

<div class="post-metadata">

**Author:** ![system](https://d2spem0quai2ol.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://staging-discuss.dev.twitch.com/u/system)\
**Post date:** [December 29, 2016, 7:18pm UTC](https://staging-discuss.dev.twitch.com/t/bot-disconnecting/8278/8 "2016-12-29T19:18:45Z")

</div>

Closed on December 29, 2016, 7:18pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
