From 768969027964e8feb7301539b3225c4e2fbfde51 Mon Sep 17 00:00:00 2001 From: wookie184 Date: Sun, 3 Apr 2022 18:56:01 +0100 Subject: Fix bug where having channels without categories causes error --- metricity/bot.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/metricity/bot.py b/metricity/bot.py index e1a691a..73125bf 100644 --- a/metricity/bot.py +++ b/metricity/bot.py @@ -94,24 +94,24 @@ async def sync_channels(guild: Guild) -> None: not isinstance(channel, CategoryChannel) and not isinstance(channel, VoiceChannel) ): + category_id = str(channel.category.id) if channel.category else None + # Cast to bool so is_staff is False if channel.category is None + is_staff = bool( + channel.category + and channel.category.id in BotConfig.staff_categories + ) if db_chan := await Channel.get(str(channel.id)): await db_chan.update( name=channel.name, - category_id=str(channel.category.id) if channel.category else None, - is_staff=( - channel.category - and channel.category.id in BotConfig.staff_categories - ), + category_id=category_id, + is_staff=is_staff, ).apply() else: await Channel.create( id=str(channel.id), name=channel.name, - category_id=str(channel.category.id) if channel.category else None, - is_staff=( - channel.category - and channel.category.id in BotConfig.staff_categories - ), + category_id=category_id, + is_staff=is_staff, ) log.info("Channel synchronisation process complete, synchronising threads") -- cgit v1.2.3