Как обойти ошибку bot was blocked by the user? Aiogram
Столкнулся с такой ошибкой 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?
Ответы (2 шт):
Автор решения: oleksandrigo
→ Ссылка
Думаю примерно так
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)
Автор решения: danyaovmi
→ Ссылка
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)
Решилось так