L
L
Loknut2022-02-26 12:45:40
Python
Loknut, 2022-02-26 12:45:40

Why doesn't the page scrolling code work?

Libraries: pyTelegramBotAPI, python-telegram-bot-paginator.
Vocabulary:

place1_pages = [
    {
        'name':'\N{Potted Plant} 90',
        'image':'imagine/41.jpg',
    },
    {
        'name':'1',
        'image':'imagine/1.jpg',
    },
    {
        'name':'2',
        'image':'imagine/2.jpg',
    },
    {
        'name':'3',
        'image':'imagine/3.jpg',
    },
    {
        'name':'4',
        'image':'imagine/4.jpg',
    },
]

The code:
import telebot

from telebot import types

from telegram_bot_pagination import InlineKeyboardPaginator
from data import place1_pages

bot = telebot.TeleBot('х')

@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, "Йоу!".format(message.from_user,bot.get_me()),
                     parse_mode='html', reply_markup=markup)

@bot.message_handler(func=lambda message: True)
def get_place1(message):
    send_place1_page(message)


@bot.callback_query_handler(func=lambda call: call.data.split('#')[0]=='place1')
def places1_page_callback(call):
    page = int(call.data.split('#')[1])
    bot.delete_message(
        call.message.chat.id,
        call.message.message_id
    )
    send_place1_page(call.message, page)


def send_place1_page(message, page=1):
    places_data = place1_pages[page-1]
    
    paginator = InlineKeyboardPaginator(
        len(place1_pages),
        current_page=page,
        data_pattern='place#{page}'
    )

    bot.send_photo(
        message.chat.id,
        open(places_data.get('image'), 'rb'), caption =places_data.get('name'),
        reply_markup=paginator.markup,
        parse_mode='Markdown'
    )


# GOOOO
bot.polling(none_stop=True)

The bot takes values ​​from the dictionary - pictures and text attached to them - and sends them to the user. These pictures can be flipped on the inline buttons below (however, the second library was created for this). When launched, the bot displays only the first photo and the text attached to it, and when you click on the online button to scroll through, nothing happens. Where is the mistake?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question