From f643863911f0cf29b7fe23d2138f358e92a4073b Mon Sep 17 00:00:00 2001 From: Eneg <42005170+Enegg@users.noreply.github.com> Date: Tue, 2 Dec 2025 00:07:30 +0100 Subject: [PATCH 1/3] from_hex_str --- disnake/colour.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/disnake/colour.py b/disnake/colour.py index ba119c546d..f0369a2c9e 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_str(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. From b55a108df652bc5b6e1da721d10e0ea744810936 Mon Sep 17 00:00:00 2001 From: Eneg <42005170+Enegg@users.noreply.github.com> Date: Tue, 2 Dec 2025 00:25:41 +0100 Subject: [PATCH 2/3] changelog --- changelog/1487.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/1487.feature.rst diff --git a/changelog/1487.feature.rst b/changelog/1487.feature.rst new file mode 100644 index 0000000000..b7d10d823a --- /dev/null +++ b/changelog/1487.feature.rst @@ -0,0 +1 @@ +Add :meth:`Colour.from_hex_str` to create :class:`Colour` from hex color codes (``#RRGGBB``). From d151bd84e0c926dd67e2b19438804d76a24dffc5 Mon Sep 17 00:00:00 2001 From: Eneg <42005170+Enegg@users.noreply.github.com> Date: Thu, 4 Dec 2025 14:12:21 +0100 Subject: [PATCH 3/3] `from_hex_str` => `from_hex` Co-authored-by: Zenith Signed-off-by: Eneg <42005170+Enegg@users.noreply.github.com> --- changelog/1487.feature.rst | 2 +- disnake/colour.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog/1487.feature.rst b/changelog/1487.feature.rst index b7d10d823a..a718efea73 100644 --- a/changelog/1487.feature.rst +++ b/changelog/1487.feature.rst @@ -1 +1 @@ -Add :meth:`Colour.from_hex_str` to create :class:`Colour` from hex color codes (``#RRGGBB``). +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 f0369a2c9e..b8ce56c291 100644 --- a/disnake/colour.py +++ b/disnake/colour.py @@ -116,7 +116,7 @@ def default(cls) -> Self: return cls(0) @classmethod - def from_hex_str(cls, hex_str: str, /) -> Self: + def from_hex(cls, hex_str: str, /) -> Self: """Constructs a :class:`Colour` from a hex color code (``#RRGGBB``). .. versionadded:: |vnext|