L
L
Loknut2022-02-07 11:24:23
Python
Loknut, 2022-02-07 11:24:23

Why is the next handler not processed?

@bot.message_handler(commands=['start'])  
def welcome(message):
    sti = open('imagine/sticker.webp', 'rb')
    bot.send_sticker(message.chat.id, sti)

    #КЛАВИАТУРА 1
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard =True)
    item = types.KeyboardButton("\N{world map}")

    markup.add(item)

    bot.send_message(message.chat.id, "Привет! /help".format(message.from_user,bot.get_me()),
                     parse_mode='html', reply_markup=markup)

@bot.message_handler(commands=['help'])
def hi1(message):
    bot.send_message (message.chat.id, "Наберите команду /go или /we")
        

@bot.message_handler(content_types=['text'])
def hi(message):
    if message.chat.type == 'private':
        if message.text == '\N{world map}':
             mesg = bot.send_message(message.chat.id, 'наберите команду /go')
             if message.text == '/go':
                 bot.register_next_step_handler(mesg, go)
        else:
            bot.send_message(message.chat.id, 'Не знаю, что и ответить \N{anguished face} \nНабери команду /help, чтобы ознакомиться со списком команд')


@bot.message_handler(commands=['go'])
def go(message):
    
    #КЛАВИАТУРА 2
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard =True)
    item1 = types.KeyboardButton("\N{baby}")
    item2 = types.KeyboardButton("\N{girl}")
    item3 = types.KeyboardButton("\N{man}")

    markup.add(item1, item2, item3)
    
    bot.send_message(message.chat.id, "Возраст?", reply_markup=markup)
    bot.register_next_step_handler(go1)

def go1(message):
    if message.chat.type == 'private':
        if message.text == '\N{baby}':

             #КЛАВИАТУРА 3
            markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard =True)
            item1 = types.KeyboardButton("игры")
            item2 = types.KeyboardButton("деньги")
            item3 = types.KeyboardButton("телки")

            markup.add(item1, item2, item3)
        
            bot.send_message(message.chat.id, 'Окей, кого вы любите больше?')
            
bot.polling(none_stop=True)

The /go command is not processed. The user is shown "I do not know what to answer." How to fix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
InternetMaster, 2022-02-07
@InternetMaster

Because you have the /go command handler below the text handler. The /go command refers to text if the handler does not catch that command before the text. Just bring up a command handler.

@bot.message_handler(commands=['start'])  
def welcome(message):
    sti = open('imagine/sticker.webp', 'rb')
    bot.send_sticker(message.chat.id, sti)

    #КЛАВИАТУРА 1
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard =True)
    item = types.KeyboardButton("\N{world map}")

    markup.add(item)

    bot.send_message(message.chat.id, "Привет! /help".format(message.from_user,bot.get_me()),
                     parse_mode='html', reply_markup=markup)

@bot.message_handler(commands=['help'])
def hi1(message):
    bot.send_message (message.chat.id, "Наберите команду /go или /we")
        
@bot.message_handler(commands=['go'])
def go(message):
    
    #КЛАВИАТУРА 2
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard =True)
    item1 = types.KeyboardButton("\N{baby}")
    item2 = types.KeyboardButton("\N{girl}")
    item3 = types.KeyboardButton("\N{man}")

    markup.add(item1, item2, item3)
    
    bot.send_message(message.chat.id, "Возраст?", reply_markup=markup)
    bot.register_next_step_handler(go1)

@bot.message_handler(content_types=['text'])
def hi(message):
    if message.chat.type == 'private':
        if message.text == '\N{world map}':
             mesg = bot.send_message(message.chat.id, 'наберите команду /go')
             if message.text == '/go':
                 bot.register_next_step_handler(mesg, go)
        else:
            bot.send_message(message.chat.id, 'Не знаю, что и ответить \N{anguished face} \nНабери команду /help, чтобы ознакомиться со списком команд')


def go1(message):
    if message.chat.type == 'private':
        if message.text == '\N{baby}':

             #КЛАВИАТУРА 3
            markup = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard =True)
            item1 = types.KeyboardButton("игры")
            item2 = types.KeyboardButton("деньги")
            item3 = types.KeyboardButton("телки")

            markup.add(item1, item2, item3)
        
            bot.send_message(message.chat.id, 'Окей, кого вы любите больше?')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question