🐛 Fix the Forbidden exception caused by the failure to send a message successfully

This commit is contained in:
洛水居室 2023-04-11 09:47:14 +08:00
parent d386a47ac7
commit f991c8b5fd
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC

View File

@ -1,5 +1,5 @@
from telegram import Chat, Update, User from telegram import Chat, Update, User
from telegram.error import NetworkError from telegram.error import NetworkError, Forbidden
from telegram.ext import CallbackContext, ChatMemberHandler from telegram.ext import CallbackContext, ChatMemberHandler
from core.config import JoinGroups, config from core.config import JoinGroups, config
@ -76,10 +76,19 @@ class ChatMember(Plugin):
if quit_status: if quit_status:
try: try:
await context.bot.send_message(chat.id, "派蒙不想进去!不是旅行者的邀请!") await context.bot.send_message(chat.id, "派蒙不想进去!不是旅行者的邀请!")
except Forbidden as exc:
logger.info("发送消息失败 %s", exc.message)
except NetworkError as exc: except NetworkError as exc:
logger.info("发送消息失败 %s", exc.message) logger.info("发送消息失败 %s", exc.message)
except Exception as exc: except Exception as exc:
logger.info("发送消息失败", exc_info=exc) logger.info("发送消息失败", exc_info=exc)
await context.bot.leave_chat(chat.id) await context.bot.leave_chat(chat.id)
else: else:
await context.bot.send_message(chat.id, "感谢邀请小派蒙到本群!请使用 /help 查看咱已经学会的功能。") try:
await context.bot.send_message(chat.id, "感谢邀请小派蒙到本群!请使用 /help 查看咱已经学会的功能。")
except Forbidden as exc:
logger.info("发送消息失败 %s", exc.message)
except NetworkError as exc:
logger.info("发送消息失败 %s", exc.message)
except Exception as exc:
logger.info("发送消息失败", exc_info=exc)