Is your program exiting because the connection is closing or is the connection closing because your program is exiting? I would suspect it’s probably the latter. If your bot isn’t going to have a UI you’ll need to look into using some sort of loop to prevent your program from exiting and the connection from closing.