Answer the question
In order to leave comments, you need to log in
How to solve aiogram.utils.exceptions.BotBlocked: Forbidden: bot was blocked by the user aiogram?
I wanted to register a mailing function using my database in a txt file, but it gives an error in the header
async def check_user():
f = open('users.txt')
users = []
for line in f:
users.append(line.replace('\n', ''))
return users
@dp.callback_query_handler(IsAdmin(), text='mail')
async def get_users_mail(call: types.CallbackQuery):
await bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=f'''<b>Введите сообщение для рассылки:</b>''', reply_markup=cancel)
await MessageMail.message.set()
@dp.message_handler(IsAdmin(), state=MessageMail.message)
async def send_users_mail(message: types.Message, state: FSMContext):
users = await check_user()
for i in users:
try:
await bot.send_message(i, message.text)
await message.answer("<b>Рассылка завершена!</b>")
await message.answer(f'''<b>Админ панель.
Доступные команды:</b>''', reply_markup=admin_menu)
except BotBlocked:
pass
await state.finish()
Answer the question
In order to leave comments, you need to log in
the message about the completion of the mailing and the output of the admin panel should be taken out of the try block and the loop, respectively.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question