From 9d0014284b8d31df96aa983a74e2a1ed1ec0f79a Mon Sep 17 00:00:00 2001 From: Jerrie <70805800+Jerrie-Aries@users.noreply.github.com> Date: Sun, 3 Oct 2021 03:16:09 +0800 Subject: [PATCH 1/3] Rename `category` to `fallback` due to shadowing names. --- core/utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/utils.py b/core/utils.py index 0fa74e457a..aaaf7e463d 100644 --- a/core/utils.py +++ b/core/utils.py @@ -393,19 +393,20 @@ async def create_thread_channel(bot, recipient, category, overwrites, *, name=No errors_raised.append((e.text, (category, name))) if "Maximum number of channels in category reached" in e.text: + fallback = None fallback_id = bot.config["fallback_category_id"] if fallback_id: fallback = discord.utils.get(category.guild.categories, id=int(fallback_id)) - if fallback and len(fallback.channels) < 49: - category = fallback + if fallback and len(fallback.channels) >= 49: + fallback = None - if not category: - category = await category.clone(name="Fallback Modmail") + if not fallback: + fallback = await category.clone(name="Fallback Modmail") bot.config.set("fallback_category_id", str(category.id)) await bot.config.update() return await create_thread_channel( - bot, recipient, category, overwrites, errors_raised=errors_raised + bot, recipient, fallback, overwrites, errors_raised=errors_raised ) if "Contains words not allowed" in e.text: From 8b69b67f22430b2adf719d5c6f0fa0ba1d605943 Mon Sep 17 00:00:00 2001 From: Jerrie <70805800+Jerrie-Aries@users.noreply.github.com> Date: Wed, 6 Oct 2021 01:55:59 +0800 Subject: [PATCH 2/3] Forgot to update the reference in `.config.set()`. --- core/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/utils.py b/core/utils.py index aaaf7e463d..2c58fe69d6 100644 --- a/core/utils.py +++ b/core/utils.py @@ -402,7 +402,7 @@ async def create_thread_channel(bot, recipient, category, overwrites, *, name=No if not fallback: fallback = await category.clone(name="Fallback Modmail") - bot.config.set("fallback_category_id", str(category.id)) + bot.config.set("fallback_category_id", str(fallback.id)) await bot.config.update() return await create_thread_channel( From b388f0eeca0ccf1200684cb278a0747fa6ada239 Mon Sep 17 00:00:00 2001 From: Jerrie <70805800+Jerrie-Aries@users.noreply.github.com> Date: Wed, 6 Oct 2021 01:57:01 +0800 Subject: [PATCH 3/3] Change default value for `errors_raised` parameter to `None`. --- core/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/utils.py b/core/utils.py index 2c58fe69d6..1fa1a95e61 100644 --- a/core/utils.py +++ b/core/utils.py @@ -376,8 +376,10 @@ def get_top_hoisted_role(member: discord.Member): return role -async def create_thread_channel(bot, recipient, category, overwrites, *, name=None, errors_raised=[]): +async def create_thread_channel(bot, recipient, category, overwrites, *, name=None, errors_raised=None): name = name or bot.format_channel_name(recipient) + errors_raised = errors_raised or [] + try: channel = await bot.modmail_guild.create_text_channel( name=name,