import telebot
bot = telebot.TeleBot('1423798151:AAFSabDxxfYdgxN9y9rAZekuc7zcvD6wXWw')
Homework1 = open('Homework.txt')
Homework = (Homework1)
@bot.message_handler(commands=['hello'])
def start_message(message):
bot.send_message(message.chat.id, 'Привет!')
@bot.message_handler(commands=['Homework', 'homework'])
def send_homework(message):
global Homework
if Homework == '':
bot.send_message(message.chat.id, 'У меня пока нет домашнего задания')
else:
bot.send_message(message.chat.id, Homework)
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text.lower() == 'пока':
bot.send_message(message.chat.id, 'Давай до свидания!')
bot.polling()
Homework = (Homework1)
with open('Homework.txt', 'r', encoding='utf-8') as f:
homework = f.read()
# ....
@bot.message_handler(commands=['Homework', 'homework'])
def send_homework(message):
if not homework:
bot.send_message(message.chat.id, 'У меня пока нет домашнего задания')
else:
bot.send_message(message.chat.id, homework)
Homework1 = open('Homework.txt','r')
Homework = Homework1.read()
Homework1.close()