S
S
smarisov6662021-12-03 10:48:50
Python
smarisov666, 2021-12-03 10:48:50

Why is the mailing list not sent to all users?

Hello everyone, the question is, why is the mailing list not sent to users of the bot?

@dp.message_handler(content_types=['photo'])
async def checker(message: types.Message):
    number = random.randint(1,999999)
    text = message.caption
    await message.photo[-1].download(f'{number}.jpg')
    photo = open(f'{number}.jpg','rb')
    users = cursor.execute("SELECT user FROM users").fetchall()
    otpr = 0
    nootpr = 0
    print(users)
    for user in users:
        try:
            await bot.send_photo(user[0],photo = photo,caption = text)
            otpr = otpr + 1
            time.sleep(0.3)
        except Exception:
            nootpr = nootpr + 1
            pass
    await bot.send_message(message.chat.id,text = f"<b>Рассылка завершена</b>\n\n<b>Отправлено: {otpr}\nНе отправлено: {nootpr}</b>",parse_mode = 'HTML')

The original result is...
61a9cbd747718462615478.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
QPDEH, 2021-12-07
@QPDEH

Who knows why, but try to add

except Exception as e:
    print(e)

Then everything will become clearer.
And do not use yet time.sleep(), otherwise the bot will wait for the entire program to complete. It is betteracyncio.sleep()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question