Пишу бот по бросанию кубиков и магическому шару в одном. Создал кнопки: бросать кубик или магический шар. Нажав на "бросать кубик" - можно выбрать количество граней.
Проблема: Бот не реагирует на второй ввод текста с клавиатуры или через кнопку. Ошибок не выдает. Не могу разобраться как заставить его принимать ввод с клавиатуры дважды подряд.
Часть написанного кода:
@bot.message_handler(commands=['start'])
def start(massage):
bot.send_message(massage.chat.id, '<b>Hello my hero, would you like to know your destiny?</b>', parse_mode='html')
photo = open('gendalf.jpg', 'rb')
bot.send_photo(massage.chat.id, photo)
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
dnd_dice = types.KeyboardButton('DnD dices')
magic_ball = types.KeyboardButton('Magic ball')
markup.add(dnd_dice, magic_ball)
bot.send_message(massage.chat.id, 'Press the button', reply_markup=markup)
@bot.message_handler(content_types=["text"])
def handle_text(antwort):
if antwort.text == 'DnD dices':
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
d4 = types.KeyboardButton('D4')
d6 = types.KeyboardButton('D6')
d8 = types.KeyboardButton('D8')
d10 = types.KeyboardButton('D10')
d12 = types.KeyboardButton('D12')
d20 = types.KeyboardButton('D20')
d100 = types.KeyboardButton('D100')
markup.add(d4, d6, d8, d10, d12, d20, d100)
bot.send_message(antwort.chat.id, 'Choose the dice you need or press the button', reply_markup=markup)
@bot.message_handler(content_types=["text"])
def try_dice(result):
try:
number = int(result.text[1:])
answer = random.randint(1, number)
bot.send_message(result.chat.id, f' You have: ☻ <b>{answer}</b> ☻', parse_mode='html')
bot.send_message(result.chat.id, 'Do you want to go on? Just write a number or press the button')
except ValueError:
try:
number = int(result.text[0:])
answer = random.randint(1, number)
bot.send_message(result.chat.id, f' You have: ☻ <b>{answer}</b> ☻', parse_mode='html')
bot.send_message(result.chat.id, 'Do you want to go on? Just write a number or press the button')
except ValueError:
bot.send_message(result.chat.id, "<b>I don't understand you.</b>", parse_mode='html')