Answer the question
In order to leave comments, you need to log in
How to nest @bot.message_handler?
Good afternoon. Today I wrote a telegram bot with the telebot library in python. The bot was supposed to be a simple calculator. But, nested @bot.message_handler in another one didn't catch messages. Please help with this problem
Ps token specially removed
import telebot
bot = telebot.TeleBot('')
keyboard_1 = telebot.types.ReplyKeyboardMarkup()
btn_1 = telebot.types.KeyboardButton('1')
btn_2 = telebot.types.KeyboardButton('2')
btn_3 = telebot.types.KeyboardButton('3')
btn_4 = telebot.types.KeyboardButton('4')
btn_5 = telebot.types.KeyboardButton('5')
btn_6 = telebot.types.KeyboardButton('6')
btn_7 = telebot.types.KeyboardButton('7')
btn_8 = telebot.types.KeyboardButton('8')
btn_9 = telebot.types.KeyboardButton('9')
btn_count = telebot.types.KeyboardButton('Считать!')
keyboard_1.row(btn_1,btn_2,btn_3)
keyboard_1.row(btn_4,btn_5,btn_6)
keyboard_1.row(btn_7,btn_8,btn_9)
keyboard_1.row(btn_count)
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, 'Привет, ты написал мне /start',reply_markup=keyboard_1)
@bot.message_handler(content_types=['text'])
def go_txt(message):
if message.text == 'Привет' :
bot.send_message(message.chat.id , 'Дароу')
elif message.text == 'Пока' :
bot.send_message(message.chat.id , 'Прощай')
elif message.text == 'ха-ха' :
bot.send_sticker(message.chat.id, 'CAADAgADcwgAAhhC7ggBnQGJ6b93ggI')
elif message.text == 'Считать!' :
bot.send_message(message.chat.id, 'Введите первое число : ')
@bot.message_handler(content_types=['text'])
def count_1(message):
firsnum = message
bot.send_message(message.chat.id, 'Введите второе число : ')
@bot.message_handler(content_types=['text'])
def count_2(message):
secnum = message
bot.send_message(message.chat.id ,secnum + firsnum )
bot.polling()
Answer the question
In order to leave comments, you need to log in
Fuck, I'm sorry, you "invested" it!?
"Lay out" and everything will be fine. Well, apart from the fact that you have to implement the concept of a user session to solve this problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question