diff --git a/changelog/1200.bugfix.rst b/changelog/1200.bugfix.rst new file mode 100644 index 0000000000..8d8387af1b --- /dev/null +++ b/changelog/1200.bugfix.rst @@ -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. diff --git a/disnake/ext/commands/cooldowns.py b/disnake/ext/commands/cooldowns.py index 354754550a..cda127398a 100644 --- a/disnake/ext/commands/cooldowns.py +++ b/disnake/ext/commands/cooldowns.py @@ -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 @@ -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)