Top.Mail.Ru
Ответы

В чём ошибка? бот на питоне не реагирует на кнопки

У меня такой код:

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
 import telebot 
from telebot import types

bot = telebot.TeleBot('') #Тут мой реальный код

str1 = types.ReplyKeyboardMarkup() 
str2 = types.ReplyKeyboardMarkup() 

 
btnD1 = types.KeyboardButton('№1') 
btnD2 = types.KeyboardButton('№2') 
btnD3 = types.KeyboardButton('№3') 
btnD4 = types.KeyboardButton('№4') 
btnD5 = types.KeyboardButton('№5') 
btnD6 = types.KeyboardButton('№6') 
btnD7 = types.KeyboardButton('№7') 
btnD8 = types.KeyboardButton('№8') 
btnD9 = types.KeyboardButton('№9') 
btnD10 = types.KeyboardButton('№10') 


 
btnL1 = types.KeyboardButton('1️⃣') 
btnP1 = types.KeyboardButton('1️⃣⏩') 
btnL2 = types.KeyboardButton('⏪2️⃣`') 
btnP2 = types.KeyboardButton('2️⃣⏩') 
 
 
str1.row(btnD1) 
str1.row(btnD2) 
str1.row(btnD3) 
str1.row(btnD4) 
str1.row(btnD5) 
str1.row(btnL1, btnP1) 
str2.row(btnD6) 
str2.row(btnD7) 
str2.row(btnD8) 
str2.row(btnD9) 
str2.row(btnD10) 
str2.row(btnL2, btnP2) 

 
@bot.message_handler(commands=['start']) 
def main(message): 
    bot.send_message(message.chat.id, 'Привет!') 
#    time.sleep(2) 
    bot.send_message(message.chat.id, 'Внизу выведены кнопки', reply_markup=str1) 
    bot.register_next_step_handler(message, on_click) 
 
def on_click(message): 
    if message.text == '️1️⃣⏩': 
        bot.send_message(message.chat.id, 'страница 2', reply_markup=str2) 
        bot.register_next_step_handler(message, on_click)

bot.polling(none_stop=True) 

Только вот проблема, после нажатия кнопки 1️⃣⏩ в чат от меня выводится 1️⃣⏩ (ну как и должно быть), но бот не меняет страницы, т.е. он просто не реагирует, даже не пишет "страница 2" и не выводит никаких ошибок

Пишу я на пайшарпе

По дате
По рейтингу
Аватар пользователя
Мудрец
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
 import telebot  
from telebot import types 
 
bot = telebot.TeleBot('') #Тут ваш реальный токен 
 
str1 = types.ReplyKeyboardMarkup()  
str2 = types.ReplyKeyboardMarkup()  
 
btnD1 = types.KeyboardButton('№1')  
btnD2 = types.KeyboardButton('№2')  
btnD3 = types.KeyboardButton('№3')  
btnD4 = types.KeyboardButton('№4')  
btnD5 = types.KeyboardButton('№5')  
btnD6 = types.KeyboardButton('№6')  
btnD7 = types.KeyboardButton('№7')  
btnD8 = types.KeyboardButton('№8')  
btnD9 = types.KeyboardButton('№9')  
btnD10 = types.KeyboardButton('№10')  
 
btnL1 = types.KeyboardButton('1️⃣')  
btnP1 = types.KeyboardButton('1️⃣⏩')  
btnL2 = types.KeyboardButton('⏪2️⃣') # Исправлена опечатка: была обратная кавычка 
btnP2 = types.KeyboardButton('2️⃣⏩')  
 
str1.row(btnD1)  
str1.row(btnD2)  
str1.row(btnD3)  
str1.row(btnD4)  
str1.row(btnD5)  
str1.row(btnL1, btnP1)  
str2.row(btnD6)  
str2.row(btnD7)  
str2.row(btnD8)  
str2.row(btnD9)  
str2.row(btnD10)  
str2.row(btnL2, btnP2)  
 
@bot.message_handler(commands=['start'])  
def main(message):  
    bot.send_message(message.chat.id, 'Привет!')  
    bot.send_message(message.chat.id, 'Внизу выведены кнопки', reply_markup=str1)  
 
# Обработчик всех текстовых сообщений вместо register_next_step_handler 
@bot.message_handler(content_types=['text']) 
def handle_text(message): 
    # Для отладки 
    print(f"Получено сообщение: {repr(message.text)}") 
     
    # Проверяем содержание сообщения 
    if '1️⃣⏩' in message.text: 
        bot.send_message(message.chat.id, 'страница 2', reply_markup=str2) 
    elif '⏪2️⃣' in message.text: 
        bot.send_message(message.chat.id, 'страница 1', reply_markup=str1) 
 
bot.polling(none_stop=True) 
Аватар пользователя
Ученик

Спасибо, большое

Аватар пользователя
Ученик

На 2ой переходит, на 3ий вроде нет
Через часа 5 скажу точно

Аватар пользователя
Ученик

Да, как я и говорил на 2ую страницу переходит, а на 3ию нет (также обратную 1ую стр не переходит)

Аватар пользователя
Ученик

Сообщение получает, а дальше никак

Аватар пользователя
Ученик

Визде

Аватар пользователя
Ученик

?



Видео по теме