Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bug): BucketType.role in cooldowns could be based on a Thread rather than Role #1200

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1200.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not use :class:`.abc.PrivateChannel` in an ``isinstance`` check as it structurally matches :class:`Thread`.
Enegg marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 4 additions & 6 deletions disnake/ext/commands/cooldowns.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from collections import deque
from typing import TYPE_CHECKING, Any, Callable, Deque, Dict, Optional

from disnake.abc import PrivateChannel
from disnake.enums import Enum
from disnake.member import Member

from .errors import MaxConcurrencyReached

Expand Down Expand Up @@ -47,11 +47,9 @@ def get_key(self, msg: Message) -> Any:
elif self is BucketType.category:
return (msg.channel.category or msg.channel).id # type: ignore
elif self is BucketType.role:
# we return the channel id of a private-channel as there are only roles in guilds
# and that yields the same result as for a guild with only the @everyone role
# NOTE: PrivateChannel doesn't actually have an id attribute but we assume we are
# recieving a DMChannel or GroupChannel which inherit from PrivateChannel and do
return (msg.channel if isinstance(msg.channel, PrivateChannel) else msg.author.top_role).id # type: ignore
# if author is not a Member we are in a private-channel context; returning its id
# yields the same result as for a guild with only the @everyone role
return (msg.author.top_role if isinstance(msg.author, Member) else msg.channel).id

def __call__(self, msg: Message) -> Any:
return self.get_key(msg)
Expand Down
Loading