add Guild.icon_url_as
Guild icons can also be up to 1024px, jpg, png, or webp
This commit is contained in:
parent
12ca0d9b16
commit
2c4876f2e7
@ -39,10 +39,13 @@ from .errors import InvalidArgument, ClientException
|
|||||||
from .channel import *
|
from .channel import *
|
||||||
from .enums import VoiceRegion, Status, ChannelType, try_enum, VerificationLevel, ContentFilter
|
from .enums import VoiceRegion, Status, ChannelType, try_enum, VerificationLevel, ContentFilter
|
||||||
from .mixins import Hashable
|
from .mixins import Hashable
|
||||||
|
from .utils import valid_icon_size
|
||||||
from .user import User
|
from .user import User
|
||||||
from .invite import Invite
|
from .invite import Invite
|
||||||
from .iterators import AuditLogIterator
|
from .iterators import AuditLogIterator
|
||||||
|
|
||||||
|
VALID_ICON_FORMATS = {"jpeg", "jpg", "webp", "png"}
|
||||||
|
|
||||||
BanEntry = namedtuple('BanEntry', 'reason user')
|
BanEntry = namedtuple('BanEntry', 'reason user')
|
||||||
|
|
||||||
class Guild(Hashable):
|
class Guild(Hashable):
|
||||||
@ -332,9 +335,40 @@ class Guild(Hashable):
|
|||||||
@property
|
@property
|
||||||
def icon_url(self):
|
def icon_url(self):
|
||||||
"""Returns the URL version of the guild's icon. Returns an empty string if it has no icon."""
|
"""Returns the URL version of the guild's icon. Returns an empty string if it has no icon."""
|
||||||
|
return self.icon_url_as()
|
||||||
|
|
||||||
|
def icon_url_as(self, *, format='webp', size=1024):
|
||||||
|
"""Returns a friendly URL version of the guild's icon. Returns and empty string if it has no icon.
|
||||||
|
|
||||||
|
The format must be one of 'webp', 'jpeg', 'jpg', or 'png'. The
|
||||||
|
size must be a power of 2 between 16 and 1024.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
-----------
|
||||||
|
format: str
|
||||||
|
The format to attempt to convert the icon to.
|
||||||
|
size: int
|
||||||
|
The size of the image to display.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
--------
|
||||||
|
str
|
||||||
|
The resulting CDN URL.
|
||||||
|
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
InvalidArgument
|
||||||
|
Bad image format passed to ``format`` or invalid ``size``.
|
||||||
|
"""
|
||||||
|
if not valid_icon_size(size):
|
||||||
|
raise InvalidArgument("size must be a power of 2 between 16 and 1024")
|
||||||
|
if format not in VALID_ICON_FORMATS:
|
||||||
|
raise InvalidArgument("format must be one of {}".format(VALID_ICON_FORMATS))
|
||||||
|
|
||||||
if self.icon is None:
|
if self.icon is None:
|
||||||
return ''
|
return ''
|
||||||
return 'https://cdn.discordapp.com/icons/{0.id}/{0.icon}.jpg'.format(self)
|
|
||||||
|
return 'https://cdn.discordapp.com/icons/{0.id}/{0.icon}.{1}?size={2}'.format(self, format, size)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def splash_url(self):
|
def splash_url(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user