Update chat.py

Added disconnect function and fixed a bug