From a960e747087a2bfc376ccec4041bdfe63d1ca89b Mon Sep 17 00:00:00 2001 From: yshtcn Date: Thu, 21 Sep 2023 17:33:19 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E5=BC=82=E5=B8=B8=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Diary Assistant.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Diary Assistant.py b/Diary Assistant.py index 0fb0508..8c8c965 100644 --- a/Diary Assistant.py +++ b/Diary Assistant.py @@ -53,13 +53,20 @@ except (FileNotFoundError, json.JSONDecodeError): user_data = {} def set_bot_commands(): - set_commands_url = URL + "setMyCommands" - commands = [ - {"command": "/done", "description": "结束记录:发送并开始新的记录."}, - {"command": "/check", "description": "检查记录,已有记录。"} - ] - response = requests.post(set_commands_url, json={"commands": commands}) - return response.json() + try: + set_commands_url = URL + "setMyCommands" + commands = [ + {"command": "done", "description": "结束记录:发送并开始新的记录."}, + {"command": "check", "description": "检查记录,已有记录。"} + ] + response = requests.post(set_commands_url, json={"commands": commands}) + response.raise_for_status() # 如果响应状态码不是200,引发HTTPError异常 + + return response.json() + except requests.HTTPError as http_err: + return f"HTTP error occurred: {http_err}" + except Exception as err: + return f"An error occurred: {err}" set_bot_commands()