Answer the question
In order to leave comments, you need to log in
How to make telegram bot accept only integer messages?
The bot should ask "How old are you?" and then show the result, but
how to make the bot accept only numerical messages (integer), and if you enter text, then let it start all over again or give an error.
I am using pyTelegramBotAPI
Answer the question
In order to leave comments, you need to log in
@bot.message_handler(content_types=['text'])
def reg_age(message):
global age
age = message.text
if age == int:
bot.send_message(message.chat.id, "Хорошо тебе! " + age + "лет")
bot.register_next_step_handler(message, next_step) # указывай какая функция будет обрабатывать следующее сообщение пользователя
else:
bot.send_message (message.chat.id, "Возраст это целое число! ")
bot.register_next_step_handler(message, reg_age) # Следущее сообщение пользователя считает функция reg_age
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question