def resolve_color(value):
"""Resolve a custom or pre-defined color.
This allows html style #123456.
"""
if value.startswith('#'):
value = value[1:] # assumes no named color starts with #
try:
intval = int(value, 16)
except ValueError:
pass
else:
if intval >= (1 << 24):
raise errors.BadArgument("Invalid color {} is too big!".format(value))
return discord.Colour(intval)
try:
return getattr(discord.Colour, value)()
except AttributeError:
raise errors.BadArgument("Invalid color {}".format(value))
评论列表
文章目录