Skip to content

Commit

Permalink
Fix bug when trying to convert a course channel when the category doe…
Browse files Browse the repository at this point in the history
…sn'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.
  • Loading branch information
VishalRamesh50 committed Oct 7, 2020
1 parent bf33cd9 commit 11ca684
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/converters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import discord
import re
from discord.ext import commands
from discord.ext.commands import (
BadArgument,
Expand Down Expand Up @@ -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.')

Expand Down

0 comments on commit 11ca684

Please sign in to comment.