@fright002

Бот не выводит встроенную клавиатуру, в чём может быть проблема?

import telebot
import random
import config
from telebot import types
from random import choice

bot = telebot.TeleBot(config.TOKEN)
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton('Расписание')
markup.add(item1)




@bot.message_handler(commands='start')
def welcome(message):
	pic = open(r'aitvaro.jfif', 'rb')
	bot.send_photo(message.chat.id, pic)

	bot.send_message(message.chat.id, 'Привет, {0.first_name}! Я -<b>{1.first_name}</b>, Бот-помощник для учеников "Айтваро Гимназии"\nМогу подсказать расписание, даты каникул, фильм на вечер и многое другое'.format(message.from_user,bot.get_me()),
	    parse_mode='html', reply_markup=markup)
	


@bot.message_handler(content_types=['text'])




def raspisanie(message):
	if message.chat.type == 'private':
		if message.text == 'Расписание':
			markup = types.InlineKeyboardMarkup(row_width=2)
			item1 = types.InlineKeyboardButton('1a', callback_data='1a')
			item2 = types.InlineKeyboardButton('1b', callback_data='1b')
			item3 = types.InlineKeyboardButton('1c', callback_data='1c')
			item4 = types.InlineKeyboardButton('1d', callback_data='1d')
			item5 = types.InlineKeyboardButton('2a', callback_data='2a')
			item6 = types.InlineKeyboardButton('2b', callback_data='2b')
			item7 = types.InlineKeyboardButton('2c', callback_data='2c')
			item8 = types.InlineKeyboardButton('2d', callback_data='2d')
			markup.add(item1, item2, item3, item4, item5, item6, item7, item8)
			bot.send_message(message.chat.id, 'Выбери свой класс')
		else:
			bot.send_message(message.chat.id, 'Я не понял этого сообщения')



@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
	pic1a = open('1a.png', 'rb')
	pic1b = open('1b.png', 'rb')
	pic1c = open('1c.png', 'rb')
	pic1d = open('1d.png', 'rb')
	pic2a = open('2a.png', 'rb')
	pic2b = open('2b.png', 'rb')
	pic2c = open('2c.png', 'rb')
	pic2d = open('2d.png', 'rb')

	try:
		if call.message:
			if call.data =='1a':
				bot.send_photo(call.message.chat.id, pic1a, 'Расписание "1а" класса')
			elif call.data =='1b':
				bot.send_photo(call.message.chat.id, pic1b, 'Расписание "1б" класса')
			elif call.data == '1c':
				bot.send_photo(call.message.chat.id, pic1c, 'Расписание "1с" класса')
			elif call.data =='1d':
				bot.send_photo(call.message.chat.id, pic1d, 'Расписание "1д" класса')
			elif call.data =='2a':
				bot.send_photo(call.message.chat.id, pic2a, 'Расписание "2а" класса')
			elif call.data == '2b':
				bot.send_photo(call.message.chat.id, pic2b, 'Расписание "2б" класса')
			elif call.data =='2c':
				bot.send_photo(call.message.chat.id, pic2c, 'Расписание "2с" класса')
			elif call.data =='2d':
				bot.send_photo(call.message.chat.id, pic2d, 'Расписание "2д" класса')

			else:
				('Такого класса нет в списке')
	except Exception as e:
		print(repr(e))			

bot.polling(none_stop=True)
  • Вопрос задан
  • 35 просмотров
Решения вопроса 1
InternetMaster
@InternetMaster
Интернет
Так ты же не привязал клавиатуру к сообщению. И кстати, ты уже назначил глобал переменную markup, хорошечно было бы её не перебивать локалом, а юзать иное название.

Привязываю исправную версию кода
import telebot
import random
import config
from telebot import types
from random import choice

bot = telebot.TeleBot(config.TOKEN)
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton('Расписание')
markup.add(item1)




@bot.message_handler(commands='start')
def welcome(message):
  pic = open(r'aitvaro.jfif', 'rb')
  bot.send_photo(message.chat.id, pic)

  bot.send_message(message.chat.id, 'Привет, {0.first_name}! Я -<b>{1.first_name}</b>, Бот-помощник для учеников "Айтваро Гимназии"\nМогу подсказать расписание, даты каникул, фильм на вечер и многое другое'.format(message.from_user,bot.get_me()),
      parse_mode='html', reply_markup=markup)
  


@bot.message_handler(content_types=['text'])
def raspisanie(message):
  if message.chat.type == 'private':
    if message.text == 'Расписание':
      markup2 = types.InlineKeyboardMarkup(row_width=2)
      item21 = types.InlineKeyboardButton('1a', callback_data='1a')
      item22 = types.InlineKeyboardButton('1b', callback_data='1b')
      item23 = types.InlineKeyboardButton('1c', callback_data='1c')
      item24 = types.InlineKeyboardButton('1d', callback_data='1d')
      item25 = types.InlineKeyboardButton('2a', callback_data='2a')
      item26 = types.InlineKeyboardButton('2b', callback_data='2b')
      item27 = types.InlineKeyboardButton('2c', callback_data='2c')
      item28 = types.InlineKeyboardButton('2d', callback_data='2d')
      markup2.add(item21, item22, item23, item24, item25, item26, item27, item28)
      bot.send_message(message.chat.id, 'Выбери свой класс', reply_markup=markup2)
    else:
      bot.send_message(message.chat.id, 'Я не понял этого сообщения')



@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
  pic1a = open('1a.png', 'rb')
  pic1b = open('1b.png', 'rb')
  pic1c = open('1c.png', 'rb')
  pic1d = open('1d.png', 'rb')
  pic2a = open('2a.png', 'rb')
  pic2b = open('2b.png', 'rb')
  pic2c = open('2c.png', 'rb')
  pic2d = open('2d.png', 'rb')

  try:
    if call.message:
      if call.data =='1a':
        bot.send_message(call.message.chat.id, pic1a, 'Расписание "1а" класса')
      elif call.data =='1b':
        bot.send_message(call.message.chat.id, pic1b, 'Расписание "1б" класса')
      elif call.data == '1c':
        bot.send_message(call.message.chat.id, pic1c, 'Расписание "1с" класса')
      elif call.data =='1d':
        bot.send_message(call.message.chat.id, pic1d, 'Расписание "1д" класса')
      elif call.data =='2a':
        bot.send_message(call.message.chat.id, pic2a, 'Расписание "2а" класса')
      elif call.data == '2b':
        bot.send_message(call.message.chat.id, pic2b, 'Расписание "2б" класса')
      elif call.data =='2c':
        bot.send_message(call.message.chat.id, pic2c, 'Расписание "2с" класса')
      elif call.data =='2d':
        bot.send_message(call.message.chat.id, pic2d, 'Расписание "2д" класса')

      else:
        ('Такого класса нет в списке')
  except Exception as e:
    print(repr(e))
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы