Skip to content
Open
Show file tree
Hide file tree
Changes from 17 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/1379.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :attr:`Role.has_gradient` and :attr:`Role.is_holographic` properties to check whether a role has a gradient or is holographic.
15 changes: 15 additions & 0 deletions disnake/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"MessageReferenceType",
"SeparatorSpacing",
"NameplatePalette",
"RoleStyle"
)

EnumMetaT = TypeVar("EnumMetaT", bound="Type[EnumMeta]")
Expand Down Expand Up @@ -2448,6 +2449,20 @@ class NameplatePalette(Enum):
white = "white"
"""White color palette."""

class RoleStyle(Enum):
"""
Specifies the style of :class:`Role`.

.. versionadded:: 2.12
"""

none = 0
"""Role without any style."""
gradient = 1
"""Role with custom gradient."""
holographic_gradient = 2
"""Role with holographic gradient."""


T = TypeVar("T")

Expand Down
13 changes: 12 additions & 1 deletion disnake/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
from typing import TYPE_CHECKING, Any, Dict, Literal, List, Optional, Union

from .asset import Asset
from .colour import Colour
from .enums import RoleStyle
from .flags import RoleFlags
from .mixins import Hashable
from .partial_emoji import PartialEmoji
Expand Down Expand Up @@ -442,6 +443,16 @@ def tertiary_color(self) -> Optional[Colour]:
.. versionadded:: 2.11
"""
return self.tertiary_colour

@property
def style(self) -> Literal[RoleStyle.none, RoleStyle.gradient, RoleStyle.holographic_gradient]:
""":class:`RoleStyle`: The role's style."""
if self.tertiary_color is not None:
return RoleStyle.holographic_gradient
elif self.secondary_color is not None and self.tertiary_color is None:
return RoleStyle.gradient
else:
return RoleStyle.none

@property
def icon(self) -> Optional[Asset]:
Expand Down
Loading