I wanna remove ReplyKeyboardMarkup
instance and show InlineKeyboardMarkup
instead, but I just can't do this by simple way as reply_markup=ReplyKeyboardRemove()
because there is inserting new InlineKeyboardMarkup
instance in code below
@dispatcher.message(Command("photo"))
async def send_random_photo(message: Message):
await bot.send_photo(
chat_id=message.chat.id,
photo=random_photo_url,
caption="Do you like this photo?)",
reply_markup=photo_inline_keyboard,
)
How can I remove a ReplyKeyboardMarkup
and then add an InlineKeyboardMarkup
?
Here's a possible straight forward approach.
(Edited)
You can remove the Keyboard with ReplyKeyboardRemove
. But, you'll have to send an additional message to do that. So, send the initial placeholder message, something like "Here's a photo", along with the ReplyKeyboardRemove
reply markup. And then, send the actual photo message with the inline reply markup.
I'm not familiar with Python, but if I'm correct, code will be something like:
@dispatcher.message(Command("photo"))
async def send_random_photo(message: Message):
# Sending the initial message with ReplyKeyboardRemove
await bot.sendMessage(
chat_id=message.chat.id,
text="Here's a photo",
reply_markup=ReplyKeyboardRemove(remove_keyboard=True),
)
await bot.send_photo(
chat_id=message.chat.id,
photo=random_photo_url,
caption="Do you like this photo?",
reply_markup=photo_inline_keyboard,
)
If you want to send ReplyKeyboardMarkup
such a way that whenever a button is pressed it should be immediately removed, you can set the one_time
property on ReplyKeyboardMarkup
to True
. Check the documentation for ReplyKeyboardMarkup.one_time. If that's the case, you don't have to send ReplyKeyboardRemove
along with the photo message, instead you can simply attach the photo_inline_keyboard
itself.
Hope this helps!