diff --git a/changelog/1487.feature.rst b/changelog/1487.feature.rst new file mode 100644 index 0000000000..a718efea73 --- /dev/null +++ b/changelog/1487.feature.rst @@ -0,0 +1 @@ +Add :meth:`Colour.from_hex` to create :class:`Colour` from hex color codes (``#RRGGBB``). diff --git a/disnake/colour.py b/disnake/colour.py index ba119c546d..b8ce56c291 100644 --- a/disnake/colour.py +++ b/disnake/colour.py @@ -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.