Ошибка в доступе к файлу

Я делаю пересылку сообщений и фото с телеграмм каналов на дискорд сервер через юзер бота. Я скачиваю фотографии на компьютер, создаю объект File из библиотеки dhooks, отправляю на хук и закрываю файл. Но при создании объекта File получаю ошибку. Самое странное, что на моем компьютере все работает, а вот на чужом ловлю ошибку

[Winerror 32] The Process cannot access the file because it is being used by another process “путь\current.jpg.temp”

@app.on_message(filters.channel)
async def hello(client : Client, message : types.Message):
    i = 0
    find = False

    for i in range(0, len(hook)):
        if (channelIds[i] == message.chat.id):
            find = True
            break

    if (find):
        username = message.chat.title

        if (message.photo):
            try:
                nameFile = "current.jpg"
                await app.download_media(message.photo, nameFile)

                picture = File("downloads/" + nameFile, name = "picture.jpg")
                hook[i].send(message.caption, file = picture, username = username)
                picture.close()

            except Exception as e:
                print(e, "\n")
                now = datetime.now()
                current_time = now.strftime("%H:%M:%S")

                print("ERROR \n" + f"title of channel: {username}\ntime: {current_time}\nmessage caption: {message.caption}")

        elif (message.text):
            hook[i].send(message.text, username = username)

Ответы (0 шт):