# My twitch plays bot keeps disconnecting from twitch

**URL:** <https://staging-discuss.dev.twitch.com/t/my-twitch-plays-bot-keeps-disconnecting-from-twitch/7137>\
**Category:** Chat and IRC\
**Created:** [August 15, 2016, 11:40am UTC](https://staging-discuss.dev.twitch.com/t/my-twitch-plays-bot-keeps-disconnecting-from-twitch/7137 "2016-08-15T11:40:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![twitchplayskh](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/twitchplayskh/32/3793_2.png) [@twitchplayskh](https://staging-discuss.dev.twitch.com/u/twitchplayskh)\
**Post date:** [August 15, 2016, 11:40am UTC](https://staging-discuss.dev.twitch.com/t/my-twitch-plays-bot-keeps-disconnecting-from-twitch/7137/1 "2016-08-15T11:40:41Z")

</div>

i have a custom twitch plays bot that me and a friend did works amazing. [https://github.com/deeredman1991/Twitch-Plays-Bot](https://github.com/deeredman1991/Twitch-Plays-Bot) but if i have it running all day it will randomly disconnect from chat and we can not work out what the bug is  
it is a Python bot that runs twitch plays kindom harts. But this bug makes it hard to keep the stream up and have cmds working

---

<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:** [August 15, 2016, 3:18pm UTC](https://staging-discuss.dev.twitch.com/t/my-twitch-plays-bot-keeps-disconnecting-from-twitch/7137/2 "2016-08-15T15:18:54Z")

</div>

The edge servers do sometimes restart and occasional connection problems aren’t exactly rare either. Your bot should detect when the connection is closed and reconnect on its own.

---

<div class="post-metadata">

**Author:** ![twitchplayskh](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/twitchplayskh/32/3793_2.png) [@twitchplayskh](https://staging-discuss.dev.twitch.com/u/twitchplayskh)\
**Post date:** [August 15, 2016, 4:24pm UTC](https://staging-discuss.dev.twitch.com/t/my-twitch-plays-bot-keeps-disconnecting-from-twitch/7137/3 "2016-08-15T16:24:44Z")

</div>

so how would we implement something like that if we do not have it

---

<div class="post-metadata">

**Author:** ![xangold](https://d1d6mrmdu7ztse.cloudfront.net/user_avatar/staging-discuss.dev.twitch.com/xangold/32/527_2.png) [@xangold](https://staging-discuss.dev.twitch.com/u/xangold)\
**Post date:** [August 16, 2016, 12:52am UTC](https://staging-discuss.dev.twitch.com/t/my-twitch-plays-bot-keeps-disconnecting-from-twitch/7137/4 "2016-08-16T00:52:54Z")

</div>

Most IRC libraries will have some way to handle a connection disconnection.

We use DNS to point at an AWS elastic load balancer. At this point we suspect that these disconnection events are due to ELB instances changing IP addresses. When an IP address changes, clients are disconnected. This is a (unfortunately) well documented issue:

> <https://stackoverflow.com/questions/3821333/amazon-ec2-elastic-load-balancer-does-its-ip-ever-change>

  

> <https://stackoverflow.com/questions/13238571/will-ip-change-for-long-running-tcp-connection-on-ec2-behind-elastic-load-balanc>

The recommendation is to handle disconnections as @3ventic mentions.

You could also periodically tear down & rebuild a connection, but that is generally unnecessary. We’re investigating more tracking of when this happens on our end, so we can understand it better.

Always appreciate data dumps (with timestamps) from you guys if you see something like this so we can correlate it with our own metrics!

---

<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:** [September 15, 2016, 12:52am UTC](https://staging-discuss.dev.twitch.com/t/my-twitch-plays-bot-keeps-disconnecting-from-twitch/7137/5 "2016-09-15T00:52:57Z")

</div>

Closed on September 15, 2016, 12:52am UTC

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