Unconnect bot from chat

I do not know what language you are using for your bot. I use Java and wrote an interface that uses WebSockets to communicate with Twitch WS IRC servers. For that, internally, I catch any error that comes from the WebSocket interface and log it and then attempt a reconnect, for example.

Your solution would be based on (a) what language you are using and (b) what library (if any) you are using.