【发布时间】:2023-01-17 11:57:24
【问题描述】:
机器人解析来自站点的数据并将所有内容写入列表。每次单击“下一步”按钮时,我都想显示上面列表中的下一张照片。
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, InputMedia
poster = ['any url photo', 'any url photo', 'any url photo']
next_btn = InlineKeyboardButton(text='next', callback_data='next')
neBTN = InlineKeyboardMarkup()
neBTN.add(next_btn)
@dp.message_handler(commands=["start"])
async def photo(message: types.Message):
file_path = poster[1]
reply_markup = neBTN
await bot.send_photo(
message.chat.id,
photo=file_path,
reply_markup=reply_markup,
caption="Test caption!",
)
@dp.callback_query_handler(text="next")
async def photo_update(query: types.CallbackQuery):
file_path = poster[2]
reply_markup = neBTN
file = InputMedia(media=file_path, caption="Updated caption :)")
await query.message.edit_media(file, reply_markup=reply_markup)
我刚刚开始与 Python 编程语言密切合作,并决定尝试创建一个机器人,但我遇到了一个我无法解决的问题。我试图通过 for 循环,但结果有点糟糕,通过单击所有照片快速更改为列表中的最后一张。
【问题讨论】:
标签: python telegram-bot aiogram