Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for widget image #9306

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
from .welcome_screen import WelcomeScreen, WelcomeChannel
from .automod import AutoModRule, AutoModTrigger, AutoModRuleAction
from .partial_emoji import _EmojiTag, PartialEmoji
from .http import Route


__all__ = (
Expand Down Expand Up @@ -137,6 +138,7 @@
VocalGuildChannel = Union[VoiceChannel, StageChannel]
GuildChannel = Union[VocalGuildChannel, ForumChannel, TextChannel, CategoryChannel]
ByCategoryItem = Tuple[Optional[CategoryChannel], List[GuildChannel]]
WidgetStyle = Literal['shield', 'banner1', 'banner2', 'banner3', 'banner4']


class BanEntry(NamedTuple):
Expand Down Expand Up @@ -3931,6 +3933,31 @@ async def widget(self) -> Widget:

return Widget(state=self._state, data=data)

def widget_image_url(self, style: WidgetStyle = 'shield') -> Optional[str]:
"""

Returns the widget image url of the guild.

.. note::

The guild must have the widget enabled to get this information.

Parameters
-----------
style: :class:`str`
The style which should be applied for the widget.
Default to ``shield``. Returns ``None`` if widget is not enabled.

Returns
--------
Optional[:class:`str`]
The widget image url in the given style.
"""
if not self.widget_enabled:
return None

return f"{Route.BASE}/guilds/{self.id}/widget.png?style={style}"

async def edit_widget(
self,
*,
Expand Down