From 10d8a03d7139798a748ba0aa3c64af11b052a417 Mon Sep 17 00:00:00 2001 From: privacy lulz <80280930+slyberries@users.noreply.github.com> Date: Wed, 1 Sep 2021 19:36:37 +0000 Subject: [PATCH] Add base -> colour support, and optimization in errors.py. --- discord/colour.py | 18 ++++++++++++++++++ discord/ext/commands/errors.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/discord/colour.py b/discord/colour.py index 927addc1..96f0f0ee 100644 --- a/discord/colour.py +++ b/discord/colour.py @@ -83,6 +83,24 @@ class Colour: raise TypeError(f'Expected int parameter, received {value.__class__.__name__} instead.') self.value: int = value + + @staticmethod + def from_hex(self, value: str, base:int = None): + """ + Initiate self.value from different base(hexidecimal, binary) + ======= + + value `str` : + + value in different base, e.g. white in hexidecimal, 0xffffff + + base `int` (optional) : + + base of your value, if you don't supply this, you have to add a prefix to your number, e.g. 0x or 0b + + """ + + return Colour(value = int(value, base=base)) def _get_byte(self, byte: int) -> int: return (self.value >> (8 * byte)) & 0xff diff --git a/discord/ext/commands/errors.py b/discord/ext/commands/errors.py index 93834385..9ea1e81a 100644 --- a/discord/ext/commands/errors.py +++ b/discord/ext/commands/errors.py @@ -110,7 +110,7 @@ class CommandError(DiscordException): from :class:`.Bot`\, :func:`.on_command_error`. """ def __init__(self, message: Optional[str] = None, *args: Any) -> None: - if message is not None: + if message: # replace 'if not none' with 'if message' # clean-up @everyone and @here mentions m = message.replace('@everyone', '@\u200beveryone').replace('@here', '@\u200bhere') super().__init__(m, *args)