deadinsult
@deadinsult

Почему питон пропускает последние 2 elif-фа?

Пытаюсь написать систему для создания рассылки для телеграм бота, но почему то последние два elif игнорируются.

код

@dp.message_handler(commands=['mail'])
async def cmd_mailing(msg: types.Message):
    uid = msg.chat.id
    conn
    adm_id = conn.execute(f'SELECT * FROM users WHERE userid ={uid}').fetchone()
    adm = adm_id[5]
    if adm == 0:
        return
    elif adm == 1:
      await msg.answer('Введите текс рассылки')
      await PostState.text.set()

@dp.message_handler(state=PostState.text)
async def text_mailing(msg: types.Message, state: FSMContext):
    await state.update_data(post_text=msg.text)
    await state.update_data(post=2)
    await state.update_data(inl=1)
    keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
    buttons = ["Да, добавить", "Нет, не надо"]
    keyboard.add(*buttons)
    await msg.answer("Хорошо, добавить картинку к рассылке?", reply_markup=keyboard)
    await PostState.get_photo.set()


@dp.message_handler(text= "Да, добавить", state=PostState.get_photo)
async def get_photo_mailing(msg: types.Message, state: FSMContext):
    await state.update_data(photo=2)
    await msg.answer("Окей, пришли мне картинку, которую хочешь прикрепить", reply_markup=types.ReplyKeyboardRemove())
    await PostState.add_photo.set()
    
@dp.message_handler(text= "Нет, не надо", state=PostState.get_photo)
async def not_photo_mailing(msg: types.Message, state: FSMContext):
    await state.update_data(photo=1)
    keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
    buttons = ["Да, добавить", "Нет, не надо"]
    keyboard.add(*buttons)
    await msg.answer("Хорошо, не хотите добавить кнопку-ссылку?", reply_markup=keyboard)
    await PostState.get_buth.set()
    
@dp.message_handler(content_types=['photo'], state=PostState.add_photo)
async def add_photo_mailing(msg: types.Message):
        keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
        buttons = ["Да, добавить", "Нет, не надо"]
        keyboard.add(*buttons)
        await msg.photo[-1].download('src/Images/im.png')
        await msg.answer("Хорошо, не хотите добавить кнопку-ссылку?", reply_markup=keyboard)
        await PostState.get_buth.set()
        
@dp.message_handler(text= "Да, добавить", state=PostState.get_buth)
async def add_buth_mailing(msg: types.Message, state: FSMContext):
    await state.update_data(inl=2)
    await msg.answer("Еще чуть чуть, пришли мне ссылку которая будет в кнопке", reply_markup=types.ReplyKeyboardRemove())
    await PostState.add_buth.set()
    
@dp.message_handler(state=PostState.add_buth)
async def add_buth_mailing(msg: types.Message, state: FSMContext):
    await state.update_data(buth_text=msg.text)
    keyboard1 = types.ReplyKeyboardMarkup(resize_keyboard=True)
    buttons1 = ["Бизнес", "Профиль"]
    buttons2 = ["Донат", "Вывод"]
    buttons3 = ["Скрыть клавиатуру"]
    keyboard1.add(*buttons1)
    keyboard1.add(*buttons2)
    keyboard1.add(*buttons3)
    data = await state.get_data()
    p1 = data['buth_text']
    p2 = data['post_text']
    p3 = data['post']
    p4 = data['photo']
    p5 = data['inl']
    qwer = msg.text
    q = checkers.is_url(qwer)
    if q == False:
        await msg.answer("Ошибка! Ссылка должна начинаться с http://или с https://!", reply_markup=keyboard1)
        await state.finish()
    else:
        keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
        buttons = ["Начать", "Отмена"]
        keyboard.add(*buttons)
        buttons_inl = [
            types.InlineKeyboardButton(text="Открыть", url=p1)
        ]
        keyboard_inl = types.InlineKeyboardMarkup(row_width=1)
        keyboard_inl.add(*buttons_inl)
        photo = open('src/Images/im.png', 'rb')
        uid = msg.chat.id
        if p3 == 2 and p4 == 2 and p5 == 2:
            await bot.send_photo(uid, photo=photo, caption=p2, reply_markup=keyboard_inl)
        elif p3 == 2 and p4 == 2 and p5 == 1:
            await bot.send_photo(uid, photo=photo, caption=p2)
        elif p3 == 2 and p4 == 1 and p5 == 1:
            await msg.answer(p2)
        await msg.answer("Начать рассылку?", reply_markup=keyboard)
        await PostState.start_mailing.set()

  • Вопрос задан
  • 115 просмотров
Решения вопроса 1
@loveapples
если последние два elif пропускаются, значит if перед ними является истинной.
если вам надо чтобы эти 2 elif выполнялись, превратите их в if.

надеюсь перед созданием вопроса вы выполняли дебаг программы.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

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

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