0

Столкнулся с такой ошибкой bot was blocked by the user aiogram. Нагуглил что можно использовать BotBlocked в aiogram, но что-то не срослось с ним. Наткнулся на ещё одну ошибку inconsistent use of tabs and spaces in indentation

async def on_startup(dispatcher):
    cursor.execute('SELECT user_id FROM test')
    arr = cursor.fetchall()
    for user_id in arr:
       await bot.send_message(chat_id=user_id[0], text="Бот запущен!")
       await asyncio.sleep(1)

Как тут грамматно расположить try except Botblocked pass?

0

2 ответа 2

0

Думаю примерно так

from aiogram.utils.exceptions import BotBlocked

async def on_startup(dispatcher):
    cursor.execute('SELECT user_id FROM test')
    arr = cursor.fetchall()
    for user_id in arr:
       try:
           await bot.send_message(chat_id=user_id[0], text="Бот запущен!")
       except BotBlocked as E:
            pass
       await asyncio.sleep(1)
1
  • Как всегда выручаете Александр:) Не помогло, уведомление не отправил, но после ошибки sqlite3.IntegrityError: UNIQUE constraint failed: test.user_id , работать не перестал
    – danyaovmi
    31 мар 2022 в 15:48
0
async def on_startup(dispatcher):
    cursor.execute('SELECT user_id FROM test')
    arr = cursor.fetchall()
    for user_id in arr:
        try:
            await bot.send_message(chat_id=user_id[0], text="Бот запущен!")
        except BotBlocked:
            await asyncio.sleep(1)

Решилось так

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.