Skip to content

Commit 20d75bb

Browse files
committed
♻️ Rewrite RoleTags.bot_id handling
1 parent 34e00c4 commit 20d75bb

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

discord/role.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@
3333
from .flags import RoleFlags
3434
from .mixins import Hashable
3535
from .permissions import Permissions
36-
from .utils import MISSING, _bytes_to_base64_data, _get_as_snowflake, snowflake_time
36+
from .utils import (
37+
MISSING,
38+
_bytes_to_base64_data,
39+
_get_as_snowflake,
40+
cached_slot_property,
41+
snowflake_time,
42+
)
3743

3844
__all__ = (
3945
"RoleTags",
@@ -85,10 +91,13 @@ class RoleTags:
8591
"_premium_subscriber",
8692
"_available_for_purchase",
8793
"_guild_connections",
94+
"_bot_id",
95+
"_bot_role",
96+
"_data",
8897
)
8998

9099
def __init__(self, data: RoleTagPayload):
91-
self.bot_id: int | None = _get_as_snowflake(data, "bot_id")
100+
self._data: RoleTagPayload = data
92101
self.integration_id: int | None = _get_as_snowflake(data, "integration_id")
93102
self.subscription_listing_id: int | None = _get_as_snowflake(
94103
data, "subscription_listing_id"
@@ -104,7 +113,13 @@ def __init__(self, data: RoleTagPayload):
104113
)
105114
self._guild_connections: Any | None = data.get("guild_connections", MISSING)
106115

107-
def is_bot_managed(self) -> bool:
116+
@cached_slot_property("_bot_id")
117+
def bot_id(self) -> int | None:
118+
"""The bot's user ID that manages this role."""
119+
return int(self._data.get("bot_id", 0) or 0) or None
120+
121+
@cached_slot_property("_bot_role")
122+
def is_bot_role(self) -> bool:
108123
"""Whether the role is associated with a bot."""
109124
return self.bot_id is not None
110125

0 commit comments

Comments
 (0)