Q
Q
qwwwwwty2021-11-18 18:48:00
Python
qwwwwwty, 2021-11-18 18:48:00

Why doesn't the bot download the image on command and send the result to the Python Aiogram user?

why doesn't the bot download the image on the command command and send the result to the user? as planned, the user must attach a photo with the "command" command, so that the bot would download the photo for this specific command and create a demotivator, send it accordingly, but nothing happens, and the console does not give errors. Most likely it's the handler, but I doubt it. in general, here is the code:

@dp.message_handler(Command(["command"], ignore_caption = False), content_types = ["photo"])
async def test (message):
    #получение ID фотографии    
    file_photo = message.photo[-1].file_id
    idfile = await bot.get_file(file_photo)

    #скачивание фотографии в директорию с ботом
    filename, file_extension = os.path.splitext(idfile.file_path)
    dowloaded_file_photo = await bot.download_file(idfile.file_path)

    src = "UserPhotosForDEM/" + "userpicture" + file_extension
    with open(src, "wb") as new_file:
        new_file.write(dowloaded_file_photo.getvalue())

    #открытие файла для будущего демотиватора + создание
    img_path3 = 'C:/Users/andis/Desktop/Python/EasyBot 2/UserPhotosForDEM'
    files3 = random.choice(list(os.walk(img_path3))[0][-1])
    img3 = open(f'{img_path3}/{files3}', 'rb')
    print(img3)
    result = random.choice(splited) + random.choice(splited2)
    print(result)
    dem = Demotivator(result) 
    dem.create(img3, RESULT_FILENAME = "userdem.jpg" ,line = "@easytelegalobby") 
    print(result)

    #отправка созданного демотиватора
    titleME = f"@{message.from_user.username}"

    await bot.send_message(message.chat.id, text = f"Демотиватор для {titleME} создан успешно✅") 
    photo22 = types.InputFile(path_or_bytesio="C:/Users/andis/Desktop/Python/EasyBot 2/userdem.jpg")
    await bot.send_photo(message.chat.id, photo = photo22)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question