Мне нужно вынести клиент в глобальную переменную что б я мог к нему обращаться через декораторы ! 

client = TelegramClient(
    args.session_file,
    args.api_id,
    args.api_hash,
    device_model=args.device_model,
    system_version=args.system_version,
    app_version=args.app_version,
    system_lang_code=args.system_lang_code,
    lang_code=args.app_lang_code,
    proxy=(socks.SOCKS5, proxy['addr'], proxy['port'], True, proxy['username'], proxy['password']),
    retry_delay=30,
    request_retries=3,
    auto_reconnect=False,
    sequential_updates=True
    )


async def main():
    proxy_change_count = 0
    exit_flag = False
    delays = [5, 10, 30, 60, 600, 1800]  # Задержки между подключениями к прокси

    while True:
        logger.info("Main начал цикл с нуля , беру прокси")
        proxy = get_new_proxy(args.country_proxy)

        if not proxy:
            logger.info("Иду получать новый прокси")
            return
        logger.info(f"взял проки и подключаюсь {proxy}")
        client = TelegramClient(
            args.session_file,
            args.api_id,
            args.api_hash,
            device_model=args.device_model,
            system_version=args.system_version,
            app_version=args.app_version,
            system_lang_code=args.system_lang_code,
            lang_code=args.app_lang_code,
            proxy=(socks.SOCKS5, proxy['addr'], proxy['port'], True, proxy['username'], proxy['password']),
            retry_delay=30,
            request_retries=3,
            auto_reconnect=False,
            sequential_updates=True
        )

        try:
            await client.connect()
            logger.info(f"Подключились к телеграмм с сессией: {args.session_file} , работаем с клиентом {client}")
            print(f"Подключились к телеграмм с сессией: {args.session_file}")

            try:
                await client.sign_in()
            except errors.AuthKeyDuplicatedError as e:

                error_message = "You must provide a phone and a code the first time, and a password only if an RPCError was raised before"
                logger.info(f"Error: {e} - Ошибка авторизации, аккаунт заблокирован или ограничен.")

                async with aiofile.async_open(args.message_file, "a", encoding="utf-8") as message_file:
                    await message_file.write(f"{error_message}\n")

                exit_flag = True

            if exit_flag:
                break

            entity_cache = {}
            connection_attempts = 0
            connected = await check_proxy(proxy)
            while not connected and connection_attempts < 5:
                connection_attempts += 1
                connected = await check_proxy(proxy)

            if not connected:
                logger.info("Иду получать новый прокси")
                if proxy_change_count < len(delays):
                    await asyncio.sleep(delays[proxy_change_count])
                    proxy_change_count += 1
                else:
                    await asyncio.sleep(random.randint(1000, 2000))
                continue

            async with client:
                client.add_event_handler(partial(message_handler, entity_cache=entity_cache), events.NewMessage(incoming=True))
                process_commands_task = client.loop.create_task(process_commands(client, args.command_file, args.message_file, args.cache_dir))
                write_status_task = client.loop.create_task(write_status(args.status_file))
                await client.run_until_disconnected()

                if await process_commands_task:
                    break
        except Exception as e:
            error_message = f"Error: {e}"
            logger.info(error_message)

            async with aiofile.async_open(args.message_file, "a", encoding="utf-8") as message_file:
                await message_file.write(f"{error_message}\n")

        if "You must provide a phone and a code the first time, and a password only if an RPCError was raised before" in error_message:
            exit_flag = True  # Устанавливаем флаг на True при возникновении ошибки

        logger.info("запрашиваю новый прокси...")
        if proxy_change_count < len(delays):
            await asyncio.sleep(delays[proxy_change_count])
            proxy_change_count += 1
        else:
            await asyncio.sleep(random.randint(600, 1800))

        if exit_flag:  # Если флаг установлен на True, выходим из цикла
            break

        continue