Skip to content

Commit

Permalink
fix(cooldown): BucketType.role could be based on a Thread rather …
Browse files Browse the repository at this point in the history
…than `Role` (#1200)

Signed-off-by: Eneg <[email protected]>
  • Loading branch information
Enegg authored Nov 29, 2024
1 parent b92f382 commit 2dab45c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/1200.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|commands| Fix usage of :attr:`~ext.commands.BucketType.role`\-type cooldowns in threads, which incorrectly operated on a per-channel basis instead.
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

0 comments on commit 2dab45c

Please sign in to comment.