Skip to content
Open
Show file tree
Hide file tree
Changes from all 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/1487.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :meth:`Colour.from_hex` to create :class:`Colour` from hex color codes (``#RRGGBB``).
8 changes: 8 additions & 0 deletions disnake/colour.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ def default(cls) -> Self:
"""A factory method that returns a :class:`Colour` with a value of ``0``."""
return cls(0)

@classmethod
def from_hex(cls, hex_str: str, /) -> Self:
"""Constructs a :class:`Colour` from a hex color code (``#RRGGBB``).

.. versionadded:: |vnext|
"""
return cls(int(hex_str.removeprefix("#"), 16))

@classmethod
def random(cls, *, seed: int | str | float | bytes | bytearray | None = None) -> Self:
"""A factory method that returns a :class:`Colour` with a random hue.
Expand Down