diff --git a/bot.py b/bot.py index 2c6f436..4ba259e 100644 --- a/bot.py +++ b/bot.py @@ -37,22 +37,30 @@ def main(): commands = Commands(config, commands_logger) - discord_client = DiscordClient(config, discord_logger, commands) - async def run_twitch_client(): twitch_client = TwitchClient(config, twitch_logger, commands) twitch_client.connect_() while True: - twitch_client.process_data() - await asyncio.sleep(TIMEOUT) + try: + twitch_client.process_data() + await asyncio.sleep(TIMEOUT) + except Exception as e: + twitch_logger.info('Exception', exc_info=e) - asyncio.ensure_future(run_twitch_client()) + async def run_discord_client(): + discord_client = DiscordClient(config, discord_logger, commands) + while True: + try: + await discord_client.start_() + except Exception as e: + discord_logger.info('Exception', exc_info=e) + await discord_client.logout() loop = asyncio.get_event_loop() try: - loop.run_until_complete(discord_client.start_()) - except: - loop.run_until_complete(discord_client.logout()) + asyncio.ensure_future(run_twitch_client()) + asyncio.ensure_future(run_discord_client()) + loop.run_forever() finally: loop.close()