import telebot
from telebot import types
from random import randint
bot = telebot.TeleBot('токен')
@bot.message_handler(commands=['start'])
def start(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
game = types.KeyboardButton('game')
markup.add(game)
bot.send_message(message.chat.id, ', {0.first_name}. Клавиатура снизу'.format(message.from_user), reply_markup = markup)
random_number = randint(1,5)
@bot.message_handler(content_types = ['text'])
def bot_message(message):
if message.chat.type == 'private':
if message.text == 'game':
if random_number == 1:
game = open('game/1.jpg', 'rb')
bot.send_photo(message.chat.id, game)
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
variant1 = types.KeyboardButton(f'{random_number + 1} кота')
variant2 = types.KeyboardButton(f'{random_number + 2} кота')
variant3 = types.KeyboardButton('1 кот')
markup.add(variant1, variant2, variant3)
bot.send_message(message.chat.id, 'Выбери правильный вариант ответа', reply_markup = markup)
elif random_number == 2:
game = open('game/2.jpg', 'rb')
bot.send_photo(message.chat.id, game)
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
variant1 = types.KeyboardButton(f'{random_number + 2} кота')
variant2 = types.KeyboardButton(f'{random_number - 1} кот')
variant3 = types.KeyboardButton('2 кота')
markup.add(variant1, variant2, variant3)
bot.send_message(message.chat.id, 'Выбери правильный вариант ответа', reply_markup = markup)
elif random_number == 3:
game = open('game/3.jpg', 'rb')
bot.send_photo(message.chat.id, game)
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
variant1 = types.KeyboardButton(f'{random_number + 2} котов')
variant2 = types.KeyboardButton('3 кота')
variant3 = types.KeyboardButton(f'{random_number - 1} кота')
markup.add(variant1, variant2, variant3)
bot.send_message(message.chat.id, 'Выбери правильный вариант ответа', reply_markup = markup)
elif random_number == 4:
game = open('game/4.jpg', 'rb')
bot.send_photo(message.chat.id, game)
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
variant1 = types.KeyboardButton('4 кота')
variant2 = types.KeyboardButton(f'{random_number - 2} кота')
variant3 = types.KeyboardButton(f'{random_number + 1} котов')
markup.add(variant1, variant2, variant3)
bot.send_message(message.chat.id, 'Выбери правильный вариант ответа', reply_markup = markup)
elif random_number == 5:
game = open('game/5.jpg', 'rb')
bot.send_photo(message.chat.id, game)
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
variant1 = types.KeyboardButton(f'{random_number - 2} кота')
variant2 = types.KeyboardButton(f'{random_number - 4} кот')
variant3 = types.KeyboardButton('5 котов')
markup.add(variant1, variant2, variant3)
bot.send_message(message.chat.id, 'Выбери правильный вариант ответа', reply_markup = markup)
# Проверка на правильные ответы
elif message.text == '1 кот' and random_number == 1:
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
chillbutton0 = types.KeyboardButton('game')
markup.add(chillbutton0)
bot.send_message(message.chat.id, 'Правильно!', reply_markup = markup)
elif message.text == '2 кота' and random_number == 2:
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
chillbutton0 = types.KeyboardButton('game')
markup.add(chillbutton0)
bot.send_message(message.chat.id, 'Правильно!', reply_markup = markup)
elif message.text == '3 кота' and random_number == 3:
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
chillbutton0 = types.KeyboardButton('game')
markup.add(chillbutton0)
bot.send_message(message.chat.id, 'Правильно!', reply_markup = markup)
elif message.text == '4 кота' and random_number == 4:
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
chillbutton0 = types.KeyboardButton('game')
markup.add(chillbutton0)
bot.send_message(message.chat.id, 'Правильно!', reply_markup = markup)
elif message.text == '5 котов' and random_number == 5:
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
chillbutton0 = types.KeyboardButton('game')
markup.add(chillbutton0)
bot.send_message(message.chat.id, 'Правильно!', reply_markup = markup)
# Проверка на НЕ правильные ответы
elif message.text == '1 кот' and random_number != 1:
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
chillbutton0 = types.KeyboardButton('game')
markup.add(chillbutton0)
bot.send_message(message.chat.id, 'Прости, ты не угадал :(', reply_markup = markup)
elif message.text == '2 кота' and random_number != 2:
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
chillbutton0 = types.KeyboardButton('game')
markup.add(chillbutton0)
bot.send_message(message.chat.id, 'Прости, ты не угадал :(', reply_markup = markup)
elif message.text == '3 кота' and random_number != 3:
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
chillbutton0 = types.KeyboardButton('game')
markup.add(chillbutton0)
bot.send_message(message.chat.id, 'Прости, ты не угадал :(', reply_markup = markup)
elif message.text == '4 кота' and random_number != 4:
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
chillbutton0 = types.KeyboardButton('game')
markup.add(chillbutton0)
bot.send_message(message.chat.id, 'Прости, ты не угадал :(', reply_markup = markup)
elif message.text == '5 котов' and random_number != 5:
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
chillbutton0 = types.KeyboardButton('game')
markup.add(chillbutton0)
bot.send_message(message.chat.id, 'Прости, ты не угадал :(', reply_markup = markup)
bot.polling()