from aiogram import types, Dispatcher from sqdb import session, user from create_bot import bot, dp @dp.message_handler(commands=['sendall']) async def sendalarm(message: types.Message): print('начал работать') if message.chat.type == 'private': if message.from_user.id == 226765676: text = message.text[9:] try: chats_id = session.query(user.chat_id).distinct() for row in chats_id: try: await bot.send_message(row[0], text) except: print('вероятно бота нет в чате') await bot.send_message(message.from_user.id, 'Сообщение успешно отправлено во все чаты') except: session.rollback() print('eror sendall') finally: session.close_all() def register_handlers_sendalarming(dp: Dispatcher): dp.register_message_handler(sendalarm)