Skip to content

Commit 9f0162c

Browse files
committed
Update in_whitelist_check to check against the parent channel, if one exists
1 parent 202b5cd commit 9f0162c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

docs/changelog.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
Changelog
55
=========
66

7+
- :release:`11.8.0 <4th September 2025>`
8+
- :feature:`305` Update :obj:`pydis_core.utils.checks.in_whitelist_check` to check against the parent channel, if one exists, instead of the ``ctx.channel.id``.
9+
710
- :release:`11.7.0 <10th August 2025>`
811
- :bug:`304 major` Update Discord invite regex to handle new protocol.
912

pydis_core/utils/checks.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
from collections.abc import Callable, Container, Iterable
3+
from typing import TYPE_CHECKING
34

45
from discord.ext.commands import (
56
BucketType,
@@ -14,6 +15,9 @@
1415

1516
from pydis_core.utils.logging import get_logger
1617

18+
if TYPE_CHECKING:
19+
import discord
20+
1721
log = get_logger(__name__)
1822

1923

@@ -74,9 +78,14 @@ def in_whitelist_check(
7478
# categories, it's probably not wise to rely on its category in any case.
7579
channels = tuple(channels) + (redirect,)
7680

77-
if channels and ctx.channel.id in channels:
78-
log.trace(f"{ctx.author} may use the `{ctx.command.name}` command as they are in a whitelisted channel.")
79-
return True
81+
if channels:
82+
# If the channel is a thread/forum post we want to check the parent channel instead.
83+
parent: discord.ForumChannel | discord.TextChannel | None = getattr(ctx.channel, "parent", None)
84+
channel_id_to_check = parent.id if parent else ctx.channel.id
85+
86+
if channel_id_to_check in channels:
87+
log.trace(f"{ctx.author} may use the `{ctx.command.name}` command as they are in a whitelisted channel.")
88+
return True
8089

8190
# Only check the category id if we have a category whitelist and the channel has a `category_id`
8291
if categories and hasattr(ctx.channel, "category_id") and ctx.channel.category_id in categories:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pydis_core"
3-
version = "11.7.0"
3+
version = "11.8.0"
44
description = "PyDis core provides core functionality and utility to the bots of the Python Discord community."
55
authors = ["Python Discord <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)