Utilities and JSON Database support #51

Closed
ghost wants to merge 6 commits from 2.0 into 2.0
Showing only changes of commit ee58f2d36c - Show all commits

View File

@@ -315,13 +315,28 @@ class Embed:
return getattr(self, '_colour', EmptyEmbed)
@colour.setter
def colour(self, value: Union[int, Colour, _EmptyEmbed]): # type: ignore
def colour(self, value: Union[int, Colour, _EmptyEmbed, str], base:int=None): # type: ignore
"""
Set colour
============
value `Union[int, Colour, _EmptyEmbed, str]`:
value of the colour. If you want to use different number systems such as hexidecimal or binary, use Colour.from_base or set it as a string in that system
base `int` (optional):
if value is a string without a prefix(0x, 0b), set base here
"""
if isinstance(value, (Colour, _EmptyEmbed)):
self._colour = value
elif isinstance(value, int):
self._colour = Colour(value=value)
elif isinstance(value, str):
self._colour = int(value, base=base)
else:
raise TypeError(f'Expected discord.Colour, int, or Embed.Empty but received {value.__class__.__name__} instead.')
raise TypeError(f'Expected discord.Colour, int, str, or Embed.Empty but received {value.__class__.__name__} instead.')
color = colour