mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-06 07:50:32 +00:00
Fix broadcast example
This commit is contained in:
parent
a139ebee6e
commit
40fd2b126b
1 changed files with 4 additions and 2 deletions
|
|
@ -23,7 +23,7 @@ def get_users():
|
|||
yield from (61043901, 78238238, 78378343, 98765431, 12345678)
|
||||
|
||||
|
||||
async def send_message(user_id: int, text: str) -> bool:
|
||||
async def send_message(user_id: int, text: str, disable_notification: bool = False) -> bool:
|
||||
"""
|
||||
Safe messages sender
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ async def send_message(user_id: int, text: str) -> bool:
|
|||
:return:
|
||||
"""
|
||||
try:
|
||||
await bot.send_message(user_id, '<b>Hello, World!</b>')
|
||||
await bot.send_message(user_id, text, disable_notification=disable_notification)
|
||||
except exceptions.BotBlocked:
|
||||
log.error(f"Target [ID:{user_id}]: blocked by user")
|
||||
except exceptions.ChatNotFound:
|
||||
|
|
@ -41,6 +41,8 @@ async def send_message(user_id: int, text: str) -> bool:
|
|||
log.error(f"Target [ID:{user_id}]: Flood limit is exceeded. Sleep {e.timeout} seconds.")
|
||||
await asyncio.sleep(e.timeout)
|
||||
return await send_message(user_id, text) # Recursive call
|
||||
except exceptions.UserDeactivated:
|
||||
log.error(f"Target [ID:{user_id}]: user is deactivated")
|
||||
except exceptions.TelegramAPIError:
|
||||
log.exception(f"Target [ID:{user_id}]: failed")
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue