From 05a51288ae3562c636673aa4763b70e14d2c4519 Mon Sep 17 00:00:00 2001 From: Ilia Miheev Date: Sat, 28 Dec 2024 14:05:45 +0300 Subject: [PATCH] Added error handling if token is missing --- bot_qr.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bot_qr.py b/bot_qr.py index 8113c48..9281dc6 100644 --- a/bot_qr.py +++ b/bot_qr.py @@ -1,18 +1,21 @@ from dotenv import load_dotenv +from sys import exit as sexit from os import remove, getenv + import telebot import qrcode - # Загрузить переменные из файла .env load_dotenv() # Получить значение переменной API_TOKEN = getenv("API_TOKEN") +if API_TOKEN is None: + print('Отсутствует токен телеграм бота. Загрузи токен в переменные окружения и бот сможет начать работу') + sexit(1) # Завершаем программу с кодом ошибки 1 bot = telebot.TeleBot(API_TOKEN) - @bot.message_handler(commands=['start']) def start(mess): bot.send_message(mess.chat.id, 'Привет. Я генерирую QR коды. Отправь мне текст и я его преобразую')