Answer the question
In order to leave comments, you need to log in
Why telegram bot can't download photos?
There is a line in the action_result method that should download the sent photo, but this does not happen. Why can this be?
available_code = ["прочитать", "закодировать"]
class Watermark(StatesGroup):
waiting_for_action = State()
waiting_for_result = State()
async def watermark_start(message: types.Message):
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
for name in available_code:
keyboard.add(name)
await message.answer("Выберите действие:", reply_markup=keyboard)
await Watermark.waiting_for_action.set()
async def action_chosen(message: types.Message, state: FSMContext):
if message.text.lower() not in available_code:
await message.answer("Пожалуйста, выберите действие, используя клавиатуру ниже.")
return
await state.update_data(action=message.text.lower())
await Watermark.next()
await message.answer("Отправьте фото")
async def action_result(message: types.Message, state: FSMContext):
if message.content_type != ContentType.PHOTO:
await message.answer("Пожалуйста, отправьте фото")
return
await message.answer("тест")
await message.photo[-1].download('test.png')
await state.finish()
def register_handlers_watermark(dp: Dispatcher):
dp.register_message_handler(watermark_start, commands="watermark", state="*")
dp.register_message_handler(action_chosen, state=Watermark.waiting_for_action)
dp.register_message_handler(action_result, state=Watermark.waiting_for_result)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question