@dmitriy8720

Как завершить цикл?

как завершить цикл, когда публикую несколько фото, нужно чтобы 1 тест появлялся, а второй нет, но появляется по количество фото и отправленным диалогам, а нужно, чтобы после 1 текста и фото, цикл завершался.

Все неуспешные попытки, в телеграм группе.
some_text = ['ключевое слово']

#Во всех примерах Отправлял 2 фото и появляется 2 одинаковых текста, 
а надо чтобы 1 текст.
@dp.message_handler(content_types=['text'])
async def handler_text_photo(message):
    for word in some_text:
        if word in message.text.lower():
            await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
            break

@dp.message_handler(content_types = ["photo"])
async def photo(message):
    for word in some_text:
        if some_text:
            await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
        break

@dp.message_handler(content_types = ["photo"])
async def photo(message):
    for num in range(1):
        await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
    if num < 1:
        pass

@dp.message_handler(content_types = ["photo"])
async def photo(message):
    counter = 0
    while True:
        if counter == 1:
            await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
        break
    counter += 1

@dp.message_handler(content_types = ["photo"])
async def photo(message):  
    for number in range(10):
        if number == 1:
            await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
            break

@dp.message_handler(content_types=['photo'])
async def photo(message):
#async def func():
    for word in some_text:
      await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')

    fileID = message.photo[-1].file_id
    file_info = await bot.get_file(fileID)
    downloaded_file = await bot.download_file(file_info.file_path)

@dp.message_handler(content_types = ["photo"])
async def photo(message):
    for word in some_text:
      await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
    file_info = await bot.get_file(message.photo[len(message.photo)-1].file_id)
    downloaded_file = await bot.download_file(file_info.file_path)
  • Вопрос задан
  • 155 просмотров
Пригласить эксперта
Ответы на вопрос 1
@Egoria
я студент, и я новенький в деле программирования
some_text = ['ключевое слово']

#Во всех примерах Отправлял 2 фото и появляется 2 одинаковых текста, 
а надо чтобы 1 текст.
@dp.message_handler(content_types=['text'])
async def handler_text_photo(message):
    for word in some_text:
        if word in message.text.lower():
            await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
            break

some_text = ['ключевое слово']

@dp.message_handler(content_types = ["photo"])
async def photo(message):
    for word in some_text:
        if some_text:
            await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
        break

some_text = ['ключевое слово']

@dp.message_handler(content_types = ["photo"])
async def photo(message):
    for num in range(1):
        await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
    if num < 1:
        pass

@dp.message_handler(content_types = ["photo"])
async def photo(message):
    counter = 0
    while True:
        if counter == 1:
            await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
        break
    counter += 1

some_text = ['ключевое слово']

@dp.message_handler(content_types = ["photo"])
async def photo(message):  
    for number in range(10):
        if number == 1:
            await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
            break

some_text = ['ключевое слово']

@dp.message_handler(content_types=['photo'])
async def photo(message):
#async def func():
    for word in some_text:
      await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')

    fileID = message.photo[-1].file_id
    file_info = await bot.get_file(fileID)
    downloaded_file = await bot.download_file(file_info.file_path)

@dp.message_handler(content_types = ["photo"])
async def photo(message):
    for word in some_text:
      await bot.send_message(message.chat.id, "Здравствуйте, {0.first_name}!\n\nЭтот текст, видит пользователь, в группе.".format(message.from_user, bot.get_me()), disable_notification=True, disable_web_page_preview=True, parse_mode='html')
    file_info = await bot.get_file(message.photo[len(message.photo)-1].file_id)
    downloaded_file = await bot.download_file(file_info.file_path)


попробуй так
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы