Можно ли как-то ожидать пока пользователь не отправит фото
У меня есть телеграм бот на Python.И надо чтобы после команды бот должен ожидать пока пользователь не отправит фото.(Знаю метод bot.register_next_step_handler() но как его применить для ожидания фото).
Ответы (1 шт):
Автор решения: Violet
→ Ссылка
def request_photo(message):
msg = bot.send_message(message.chat.id, 'Отправьте мне фото')
bot.register_next_step_handler(msg, ticket_get_photo)
def get_photo(message):
if message.content_type == 'photo':
file_info = bot.get_file(message.photo[len(message.photo) - 1].file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = dpath + 'user_data/{}/'.format(message.chat.id) + file_info.file_path
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
else: # запрашиваем ещё раз, если не фото
msg = bot.send_message(message.chat.id, 'Отправьте мне фото')
bot.register_next_step_handler(msg, get_photo)