From f991c8b5fdb2327b62341b182f0590e064664171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Tue, 11 Apr 2023 09:47:14 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20the=20`Forbidden`=20except?= =?UTF-8?q?ion=20caused=20by=20the=20failure=20to=20send=20a=20message=20s?= =?UTF-8?q?uccessfully?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/system/chat_member.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/system/chat_member.py b/plugins/system/chat_member.py index dc9fd4c7..44715ae5 100644 --- a/plugins/system/chat_member.py +++ b/plugins/system/chat_member.py @@ -1,5 +1,5 @@ from telegram import Chat, Update, User -from telegram.error import NetworkError +from telegram.error import NetworkError, Forbidden from telegram.ext import CallbackContext, ChatMemberHandler from core.config import JoinGroups, config @@ -76,10 +76,19 @@ class ChatMember(Plugin): if quit_status: try: await context.bot.send_message(chat.id, "派蒙不想进去!不是旅行者的邀请!") + 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) await context.bot.leave_chat(chat.id) 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)