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)
|
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
|
Safe messages sender
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ async def send_message(user_id: int, text: str) -> bool:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
try:
|
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:
|
except exceptions.BotBlocked:
|
||||||
log.error(f"Target [ID:{user_id}]: blocked by user")
|
log.error(f"Target [ID:{user_id}]: blocked by user")
|
||||||
except exceptions.ChatNotFound:
|
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.")
|
log.error(f"Target [ID:{user_id}]: Flood limit is exceeded. Sleep {e.timeout} seconds.")
|
||||||
await asyncio.sleep(e.timeout)
|
await asyncio.sleep(e.timeout)
|
||||||
return await send_message(user_id, text) # Recursive call
|
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:
|
except exceptions.TelegramAPIError:
|
||||||
log.exception(f"Target [ID:{user_id}]: failed")
|
log.exception(f"Target [ID:{user_id}]: failed")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue