Skip to content

Commit 696dcbf

Browse files
committed
♻️ Rewrite RoleTags.bot_id handling
1 parent 34e00c4 commit 696dcbf

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

discord/role.py

Lines changed: 18 additions & 4 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",
@@ -79,16 +85,18 @@ class RoleTags:
7985
"""
8086

8187
__slots__ = (
82-
"bot_id",
8388
"integration_id",
8489
"subscription_listing_id",
8590
"_premium_subscriber",
8691
"_available_for_purchase",
8792
"_guild_connections",
93+
"_bot_id",
94+
"_bot_role",
95+
"_data",
8896
)
8997

9098
def __init__(self, data: RoleTagPayload):
91-
self.bot_id: int | None = _get_as_snowflake(data, "bot_id")
99+
self._data: RoleTagPayload = data
92100
self.integration_id: int | None = _get_as_snowflake(data, "integration_id")
93101
self.subscription_listing_id: int | None = _get_as_snowflake(
94102
data, "subscription_listing_id"
@@ -104,7 +112,13 @@ def __init__(self, data: RoleTagPayload):
104112
)
105113
self._guild_connections: Any | None = data.get("guild_connections", MISSING)
106114

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

0 commit comments

Comments
 (0)