disnake icon indicating copy to clipboard operation
disnake copied to clipboard

feat(Colour): factory method for `#RRGGBB` color codes

Open Enegg opened this issue 1 month ago • 2 comments

Summary

This PR adds a new factory method .from_hex_str to disnake.Colour which accepts strings in the form of "#RRGGBB". This is particularly useful in code editors that provide a color picker when they detect a color code. VSCode displaying colored squares next to color codes

Checklist

  • [x] If code changes were made, then they have been tested
    • [x] I have updated the documentation to reflect the changes
    • [x] I have formatted the code properly by running uv run nox -s lint
    • [x] I have type-checked the code by running uv run nox -s pyright
  • [ ] This PR fixes an issue
  • [x] This PR adds something new (e.g. new method or parameters)
  • [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • [ ] This PR is not a code change (e.g. documentation, README, ...)

Enegg avatar Dec 01 '25 23:12 Enegg

ext.commands.ColourConverter also handles hex colors of various formats, it could probably make use of this new method too.

shiftinv avatar Dec 02 '25 18:12 shiftinv

ext.commands.ColourConverter also handles hex colors of various formats, it could probably make use of this new method too.

I did expect there being a converter for this, but I'm not convinced this simple method is going to be of much use to it.

I can see these two relevant methods: https://github.com/DisnakeDev/disnake/blob/9ebc9deac902989e6d0c96e93f8726aeb14e4af9/disnake/ext/commands/converter.py#L705-L714 https://github.com/DisnakeDev/disnake/blob/9ebc9deac902989e6d0c96e93f8726aeb14e4af9/disnake/ext/commands/converter.py#L738-L757

...but they perform work/validation that goes beyond simply stripping the leading # and parsing as base 16. It also seems to support 3-digit #RGB format.

Enegg avatar Dec 04 '25 14:12 Enegg