From a47558aa2840b541b3dbc525099008e7e10bd196 Mon Sep 17 00:00:00 2001 From: Mariana Meireles Date: Sat, 15 Jan 2022 16:42:33 -0800 Subject: [PATCH] Fix printing for headers and req. url. Add error handling for invite creation --- app.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 1e55233..2233075 100644 --- a/app.py +++ b/app.py @@ -64,12 +64,16 @@ def recaptcha(token): def invite(): print("Generating new invite!") resp = requests.post( - 'https://discordapp.com/api/channels/%s/invites' % config["discord"]["welcome_room"], - headers={'Authorization': 'Bot %s' % config["discord"]["private"]}, - json={'max_uses': 1, 'unique': True, 'expires': 300} + 'https://discordapp.com/api/channels/{}/invites'.format(config["discord"]["welcome_room"]), + headers={'Authorization': 'Bot {}'.format(config["discord"]["private"])}, + json={'max_uses': 1, 'unique': True, 'max_age': 300} ) i = resp.json() - print("Generated new invite!") + # error handling for invite creation + if (i.get('code')): + print("Generated new invite!") + else: + print(i) return i["code"] app = Flask(__name__)