From 11ca68464aa35e06306769a670b2b5df301104c2 Mon Sep 17 00:00:00 2001 From: Vishal Ramesh Date: Tue, 6 Oct 2020 20:22:35 -0400 Subject: [PATCH] Fix bug when trying to convert a course channel when the category doesn't exist - Previously if a category didn't exist it would evaluate to None when getting and so it would throw a AttributeError when iterating through the channels to check if that course existed. - Now it only checks if the category exists and otherwise lets it throw a BadArgument Exception. --- src/converters.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/converters.py b/src/converters.py index 105612c..79aff7c 100644 --- a/src/converters.py +++ b/src/converters.py @@ -1,5 +1,4 @@ import discord -import re from discord.ext import commands from discord.ext.commands import ( BadArgument, @@ -40,12 +39,15 @@ async def convert( course_category, course_num = [w.upper() for w in argument.split("-")] else: course_category, course_num = [w.upper() for w in argument.split(" ")] - category: discord.CategoryChannel = discord.utils.get( + category: Optional[discord.CategoryChannel] = discord.utils.get( guild.categories, name=course_category ) - for c in category.text_channels: - if c.topic and c.topic.startswith(f"{course_category}-{course_num}"): - return c + if category is not None: + for c in category.text_channels: + if c.topic and c.topic.startswith( + f"{course_category}-{course_num}" + ): + return c raise BadArgument(f'Course "{argument}" not found.') raise BadArgument(f'"{argument}" is an invalid course format.')