aboutsummaryrefslogtreecommitdiffstats
path: root/bot
diff options
context:
space:
mode:
Diffstat (limited to 'bot')
-rw-r--r--bot/exts/utilities/colour.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/bot/exts/utilities/colour.py b/bot/exts/utilities/colour.py
index c2a5e7e7..7b128393 100644
--- a/bot/exts/utilities/colour.py
+++ b/bot/exts/utilities/colour.py
@@ -130,7 +130,13 @@ class Colour(commands.Cog):
"""Command to create an embed from a HEX input."""
if "#" not in hex_code:
hex_code = f"#{hex_code}"
+ if len(hex_code) not in (4, 5, 7, 9) or any(_ not in string.hexdigits+"#" for _ in hex_code):
+ raise commands.BadArgument(
+ message=f"HEX values must be hexadecimal and take the form *#RRGGBB* or *#RGB*. User input was: `{hex_code}`.")
+
hex_tuple = ImageColor.getrgb(hex_code)
+ if len(hex_tuple) == 4:
+ hex_tuple = hex_tuple[:-1] # color must be RGB. If RGBA, we remove the alpha value
await self.send_colour_response(ctx, hex_tuple)
@colour.command()