Telebot API in python keeps disconnecting

Using telebot, keeps disconnecting from service. Ive temporarily made it just restart whenever this happens. Below is my code and error:

import random
import telebot
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
from threading import Timer, Event
from dotenv import load_dotenv
import os

import gptStuff

load_dotenv()
telegramKey = os.getenv('telegramKey')
bot = telebot.TeleBot(telegramKey)

user_state = {}
user_timers = {}
user_word = {}
wordList = []
with open('data/words.txt', 'r', encoding='utf-8') as file:
    for line in file:
        wordList.append(line.strip())

wordDef = {}
for i in wordList:
    sp = i.split(" - ")
    wordDef[sp[0]] = sp[1]


def doGrammarStuff(chat_id):
    wordNum = random.randint(0, len(wordList) - 1)
    cW = wordList[wordNum].split(" - ")
    user_word[chat_id] = cW[0]
    return cW[0]


def reset_state(chat_id):
    global user_state
    if chat_id in user_state:
        del user_state[chat_id]


def cancel_timer(chat_id):
    if chat_id in user_timers:
        user_timers[chat_id][1].set()
        user_timers[chat_id][0].cancel()
        del user_timers[chat_id]


def send_main_menu(chat_id):
    bot.send_message(chat_id, "Якщо вам треба зі мною зв'язатись, @RomanVarenyk")
    markup = InlineKeyboardMarkup()
    markup.row_width = 1
    markup.add(
        InlineKeyboardButton("Слова", callback_data='words'),
        InlineKeyboardButton("Граматика", callback_data='grammar'),
        InlineKeyboardButton("Задайте питання про англійську! (експерементально)", callback_data='convo')
    )
    bot.send_message(chat_id, "Оберіть що ви хочете зробити", reply_markup=markup)
    reset_state(chat_id)
    cancel_timer(chat_id)


def send_word_prompt(chat_id):
    currentWord = doGrammarStuff(chat_id)
    bot.send_message(chat_id, f'Слово: {currentWord}')
    markup = InlineKeyboardMarkup()
    markup.row_width = 1
    markup.add(
        InlineKeyboardButton("Показати", callback_data='show'))
    bot.send_message(chat_id,
                     "У вас є 1 хвилина щоб згадати слово, І натиснути кнопку показати. Якщо не натисните то ви повернетесь в головне меню",
                     reply_markup=markup)
    user_state[chat_id] = 'waiting_for_word'
    reset_timer(chat_id)


def reset_timer(chat_id):
    cancel_timer(chat_id)
    stop_event = Event()
    timer = Timer(300.0, send_main_menu_if_inactive, [chat_id, stop_event])
    user_timers[chat_id] = (timer, stop_event)
    timer.start()


def send_main_menu_if_inactive(chat_id, stop_event):
    if not stop_event.is_set():
        send_main_menu(chat_id)


@bot.message_handler(commands=['start'])
def start(message):
    send_main_menu(message.chat.id)


def doGrammar(chat_id):
    bot.send_message(chat_id, "Що ви хочете по практикуватись в граматиці?")
    user_state[chat_id] = 'waiting_grammar'


@bot.callback_query_handler(func=lambda call: True)
def callback_query(call):
    global user_state

    if call.data == 'words':
        send_word_prompt(call.message.chat.id)
        reset_timer(call.message.chat.id)

    elif call.data == 'show':
        markup = InlineKeyboardMarkup()
        markup.row_width = 1
        markup.add(
            InlineKeyboardButton("Продовжити", callback_data='words'),
            InlineKeyboardButton("В головне меню", callback_data='stop')
        )
        bot.send_message(call.message.chat.id,
                         f"The definition of the word is: {wordDef.get(user_word.get(call.message.chat.id))}",
                         reply_markup=markup)
        doGrammarStuff(call.message.chat.id)
        reset_timer(call.message.chat.id)
        reset_state(call.message.chat.id)

    elif call.data == 'grammar':
        doGrammar(call.message.chat.id)
        reset_timer(call.message.chat.id)
        user_state[call.message.chat.id] = 'waiting_grammar'

    elif call.data == 'convo':
        bot.send_message(call.message.chat.id, "Яке у вас питання?")
        user_state[call.message.chat.id] = 'await_ai_response'
        reset_timer(call.message.chat.id)

    elif call.data == 'continue':
        send_word_prompt(call.message.chat.id)
        reset_timer(call.message.chat.id)
        user_state[call.message.chat.id] = 'waiting_grammar'


    elif call.data == 'stop':
        send_main_menu(call.message.chat.id)
        reset_timer(call.message.chat.id)
        reset_state(call.message.chat.id)


@bot.message_handler(func=lambda message: True)
def handle_message(message):
    global user_state, gptRes

    chat_id = message.chat.id

    if chat_id in user_state and user_state[chat_id] == 'waiting_grammar':
        bot.send_message(chat_id, 'Почекайте будь ласка')
        gptRes = gptStuff.grammar(message.text.lower())
        user_state[chat_id] = 'grammar_response_wait'
        markup = InlineKeyboardMarkup()
        markup.row_width = 1
        markup.add(
            InlineKeyboardButton("В головне меню", callback_data='stop')
        )
        bot.send_message(chat_id, gptRes, reply_markup=markup)


    elif chat_id in user_state and user_state[chat_id] == 'grammar_response_wait':
        bot.send_message(chat_id, gptStuff.answerCheck(message.text, gptRes))
        markup = InlineKeyboardMarkup()
        markup.row_width = 1
        markup.add(
            InlineKeyboardButton("В головне меню", callback_data='stop'),
            InlineKeyboardButton("Продовжити", callback_data='grammar')
        )
        bot.send_message(chat_id, "Хочете продовжити?", reply_markup=markup)
        user_state[chat_id] = 'waiting_grammar'


    elif chat_id in user_state and user_state[chat_id] == 'await_ai_response':
        bot.send_message(chat_id, 'Почекайте будь ласка')
        bot.send_message(chat_id, gptStuff.askQuestions(message.text))
        send_main_menu(chat_id)
        reset_state(chat_id)


def main():
    bot.polling(none_stop=True)


if __name__ == '__main__':
    main()

If possible I would like to make it so that the program does not need to restart every time it disconnects, could anyone please help out?

PS: error is in the comments

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật