Пишу бота на Pythone, бот почему-то никак не откликается на текст, не могу понять почему
@bot.message_handler(content_types=['text'])
def chto_hochesh_first(message):
if message.chat.type == 'private':
if message.text == 'ДЗ':
third_choice = types.ReplyKeyboardMarkup(row_width=2)
fizika = types.KeyboardButton("Физика")
math = types.KeyboardButton("Вышмат")
history = types.KeyboardButton('История')
rusk = types.KeyboardButton('Русский')
vvp = types.KeyboardButton('ВВП')
vvit = types.KeyboardButton('ВВИТ')
inostr = types.KeyboardButton('Ин.яз.')
exitt = types.KeyboardButton('Назад')
third_choice.add(fizika, math, history, rusk, vvp, vvit, inostr, exitt)
bot.send_message(message.chat.id, 'Выбери предмет', reply_markup=third_choice)
elif message.text == 'Лекции':
second_choice = types.InlineKeyboardMarkup(row_width=2)
fizikalec = types.InlineKeyboardButton("Физика лекции", callback_data='fizika')
mathlec = types.InlineKeyboardButton("Вышмат лекции", callback_data='math')
historylec = types.InlineKeyboardButton('История лекции', callback_data='history')
rusklec = types.InlineKeyboardButton('Русский лекции', callback_data='rusk')
vvplec = types.InlineKeyboardButton('ВВП лекции', callback_data='vvp')
vvitlec = types.InlineKeyboardButton('ВВИТ лекции', callback_data='vvit')
inostrlec = types.InlineKeyboardButton('Ин.яз. лекции', callback_data='inostr')
exitt = types.InlineKeyboardButton('Назад', callback_data='exitt')
second_choice.add(fizikalec, mathlec, historylec, rusklec, vvplec, vvitlec, inostrlec, exitt)
bot.send_message(message.chat.id, 'Выбери предмет', reply_markup=second_choice)
elif message.text == 'Расписание':
fourth_choice = types.ReplyKeyboardMarkup(row_width=2)
@bot.message_handler(content_types=['text'])
def chto_hochesh_second(message):
if message.chat.type == 'private':
if message.text == 'Физика':
bot.send_message(message.chat.id, 'Достать учебник Савельева Общая физика какая-то там')
elif message.text == 'Вышмат':
bot.send_message(message.chat.id, 'Тут ДЗ')
elif message.text == 'История':
bot.send_message(message.chat.id, 'Тут ДЗ')
elif message.text == 'Русский':
bot.send_message(message.chat.id, 'Тут ДЗ')
elif message.text == 'ВВП':
bot.send_message(message.chat.id, 'Тут ДЗ')
elif message.text == 'ВВИТ':
bot.send_message(message.chat.id, 'Тут ДЗ')
elif message.text == 'Ин.яз.':
bot.send_message(message.chat.id, 'Тут ДЗ')
elif message.text == 'Назад':
first_choice = types.ReplyKeyboardMarkup(resize_keyboard=True)
dz = types.KeyboardButton('ДЗ')
lections = types.KeyboardButton('Лекции')
timetable = types.KeyboardButton('Расписание')
first_choice.add(dz, lections, timetable)
bot.send_message(message.chat.id,'Назад'.format(message.from_user,bot.get_me()),parse_mode='html', reply_markup=first_choice)
bot.infinity_polling()
из функции chto_hochesh_second, когда боту поступает текст например "Физика", то он ничего не выводит, с остальным условием всё также не выводит, даже кнопку "Назад", не могу понять в чём проблема.
Ответы (1 шт):
Автор решения: ZxNuClear
→ Ссылка
UPD
С данной библиотекой особо не работал, но если "грязно", то как-то так:
@bot.message_handler(content_types=['text'])
def chto_hochesh_first(message):
if message.chat.type == 'private':
first_choice = types.InlineKeyboardMarkup(row_width=3)
dz = types.InlineKeyboardButton('ДЗ', callback_data='dz')
lections = types.InlineKeyboardButton('Лекции', callback_data='lec')
timetable = types.InlineKeyboardButton('Расписание', callback_data='rasp')
first_choice.add(dz, lections, timetable)
bot.send_message(message.chat.id,'Выбери тему'.format(message.from_user,bot.get_me()),parse_mode='html', reply_markup=first_choice)
@bot.callback_query_handler(func=lambda call: True)
def callback_function1(call: telebot.types.CallbackQuery):
if call.data == "dz":
keyboard = types.InlineKeyboardMarkup(row_width=2)
fizikadz = types.InlineKeyboardButton("Физика ДЗ", callback_data='fizikadz')
mathdz = types.InlineKeyboardButton("Вышмат ДЗ", callback_data='mathdz')
historydz = types.InlineKeyboardButton('История ДЗ', callback_data='historydz')
ruskdz = types.InlineKeyboardButton('Русский ДЗ', callback_data='ruskdz')
exit = types.InlineKeyboardButton('Назад', callback_data='exit')
keyboard.add(fizikadz, mathdz, historydz, ruskdz, exit)
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Выбери предмет", reply_markup=keyboard)
elif call.data == "lec":
keyboard = types.InlineKeyboardMarkup(row_width=2)
fizikalec = types.InlineKeyboardButton("Физика Лекции", callback_data='fizikalec')
mathlec = types.InlineKeyboardButton("Вышмат Лекции", callback_data='mathlec')
historylec = types.InlineKeyboardButton('История Лекции', callback_data='historylec')
rusklec = types.InlineKeyboardButton('Русский Лекции', callback_data='rusklec')
exit = types.InlineKeyboardButton('Назад', callback_data='exit')
keyboard.add(fizikalec, mathlec, historylec, rusklec, exit)
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Выбери предмет", reply_markup=keyboard)
elif call.data == "rasp":
keyboard = types.InlineKeyboardMarkup(row_width=2)
fizikarasp = types.InlineKeyboardButton("Физика Расписание", callback_data='fizikarasp')
mathrasp = types.InlineKeyboardButton("Вышмат Расписание", callback_data='mathrasp')
historyrasp = types.InlineKeyboardButton('История Расписание', callback_data='historyrasp')
ruskrasp = types.InlineKeyboardButton('Русский Расписание', callback_data='ruskrasp')
exit = types.InlineKeyboardButton('Назад', callback_data='exit')
keyboard.add(fizikarasp, mathrasp, historyrasp, ruskrasp, exit)
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Выбери предмет", reply_markup=keyboard)
elif call.data == "exit":
keyboard = types.InlineKeyboardMarkup(row_width=3)
dz = types.InlineKeyboardButton('ДЗ', callback_data='dz')
lections = types.InlineKeyboardButton('Лекции', callback_data='lec')
timetable = types.InlineKeyboardButton('Расписание', callback_data='rasp')
keyboard.add(dz, lections, timetable)
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Выбери тему", reply_markup=keyboard)
elif call.data == "fizikadz":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Домашнее задание по Физике')
elif call.data == "fizikalec":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Лекция по Физике')
elif call.data == "fizikarasp":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Расписание по Физике')
elif call.data == "mathdz":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Домашнее задание по Вышмату')
elif call.data == "mathlec":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Лекция по Вышмату')
elif call.data == "mathrasp":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Расписание по Вышмату')
elif call.data == "historydz":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Домашнее задание по Истории')
elif call.data == "historylec":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Лекция по Истории')
elif call.data == "historyrasp":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Расписание по Истории')
elif call.data == "ruskdz":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Домашнее задание по Русскому')
elif call.data == "rusklec":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Лекция по Русскому')
elif call.data == "ruskrasp":
bot.delete_message(call.message.chat.id, call.message.id)
bot.send_message(call.message.chat.id, 'Тут Расписание по Русскому')
bot.answer_callback_query(callback_query_id=call.id)
bot.infinity_polling()