Пробую сделать в телеграм боте, чтобы при нажатии на инлайн кнопки в сообщении изменялась картинка. Картинка с инлайн кнопками появляется, но не изменяется. Помогите. Не могу найти урок по теме.
from aiogram import Dispatcher
from main import bot
from database.pictures import im1, im2, im3
import aiogram.types as types
images = [im1, im2, im3]
current_image = 0
dp = Dispatcher(bot)
async def cmd_photo(message: types.Message):
keyboard = types.InlineKeyboardMarkup()
keyboard.row(types.InlineKeyboardButton(text='←', callback_data='left'),
types.InlineKeyboardButton(text='→', callback_data='right'))
await bot.send_photo(chat_id=message.chat.id, photo=images[current_image], reply_markup=keyboard)
async def change_image_callback_handler(query: types.CallbackQuery):
global current_image
if query.data == 'left':
current_image = (current_image - 1) % len(images)
elif query.data == 'right':
current_image = (current_image + 1) % len(images)
keyboard = types.InlineKeyboardMarkup()
keyboard.row(types.InlineKeyboardButton(text='←', callback_data='left'),
types.InlineKeyboardButton(text='→', callback_data='right'))
await query.message.edit_media(media=types.InputMediaPhoto(media=images[current_image]), reply_markup=keyboard)
def register_handlers_change_photo(dp: Dispatcher):
dp.register_message_handler(cmd_photo, commands="Фото")
dp.register_callback_query_handler(change_image_callback_handler)