From b897740e76530abe270d7091add964d45599a9d2 Mon Sep 17 00:00:00 2001 From: phxntxm Date: Sun, 23 Sep 2018 00:18:13 -0500 Subject: [PATCH] Change order of channel checking to ensure it exists --- cogs/birthday.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cogs/birthday.py b/cogs/birthday.py index 093996e..940b1f4 100644 --- a/cogs/birthday.py +++ b/cogs/birthday.py @@ -88,14 +88,18 @@ class Birthday: if not server: continue + # Set our default to either the one set + default_channel_id = s.get('notifications', {}).get('default') + # If it is has been overriden by picarto notifications setting, use this + channel_id = s.get('notifications', {}).get('birthday') or default_channel_id + if not channel_id: + continue + + # Now get the channel based on that ID + channel = server.get_channel(int(channel_id)) + bds = self.get_birthdays_for_server(server, today=True) for bd in bds: - # Set our default to either the one set - default_channel_id = s.get('notifications', {}).get('default') - # If it is has been overriden by picarto notifications setting, use this - channel_id = s.get('notifications', {}).get('birthday') or default_channel_id - # Now get the channel based on that ID - channel = server.get_channel(int(channel_id)) try: await channel.send("It is {}'s birthday today! " "Wish them a happy birthday! \N{SHORTCAKE}".format(bd['member'].mention))