From a98324fbf84a5ad1bce5ab9c8385e9fe4574dcfe Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 30 Sep 2015 19:58:19 +0200 Subject: [PATCH] Add handling of login failure in examples Check and handle login failure in the examples provided for using this library. This is a common error condition that should be handled by any script using this library. --- examples/deleted.py | 4 ++++ examples/echo.py | 4 ++++ examples/edits.py | 4 ++++ examples/reply.py | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/examples/deleted.py b/examples/deleted.py index 7f77e9c38..3b6b98978 100644 --- a/examples/deleted.py +++ b/examples/deleted.py @@ -3,6 +3,10 @@ import discord client = discord.Client() client.login('email', 'password') +if not client.is_logged_in: + print('Logging in to Discord failed') + exit(1) + @client.event def on_ready(): print('Connected!') diff --git a/examples/echo.py b/examples/echo.py index ce5eef901..d2b4b20fe 100644 --- a/examples/echo.py +++ b/examples/echo.py @@ -3,6 +3,10 @@ import discord client = discord.Client() client.login('email', 'password') +if not client.is_logged_in: + print('Logging in to Discord failed') + exit(1) + @client.event def on_ready(): print('Connected!') diff --git a/examples/edits.py b/examples/edits.py index e8233bbb0..cb07dc6b3 100644 --- a/examples/edits.py +++ b/examples/edits.py @@ -4,6 +4,10 @@ import time client = discord.Client() client.login('email', 'password') +if not client.is_logged_in: + print('Logging in to Discord failed') + exit(1) + @client.event def on_ready(): print('Connected!') diff --git a/examples/reply.py b/examples/reply.py index f3f56c72c..0697704da 100644 --- a/examples/reply.py +++ b/examples/reply.py @@ -3,6 +3,10 @@ import discord client = discord.Client() client.login('email', 'password') +if not client.is_logged_in: + print('Logging in to Discord failed') + exit(1) + @client.event def on_message(message): if message.content.startswith('!hello'):