From 2b744a7cf84a7f83b23cdcc34e6be948462548bf Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Tue, 12 Dec 2023 15:13:34 +1100 Subject: [PATCH] fix: Discord api --- main.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 53f5bdf..767a421 100644 --- a/main.py +++ b/main.py @@ -177,12 +177,21 @@ def update_address(): if 'address' not in r.json(): print("Error: " + r.text,flush=True) # Send alert via discord - webhook = os.getenv('webhook') - if webhook != None: - payload = { - "content": "Error: " + r.text - } - r = requests.post(webhook, data=json.dumps(payload), headers=headers) + url = os.getenv('discord_webhook') + if url == None: + return "No webhook set" + + payload = { + "content": "NB cookie has expired\n@everyone" + } + response = requests.post(url, data=json.dumps(payload), headers={'Content-Type': 'application/json'}) + + # Check if the message was sent successfully + if response.status_code == 204: + print("Message sent successfully!") + else: + print(f"Failed to send message. Status code: {response.status_code}") + print(response.text) return address = r.json()['address']