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 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 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 @@ -3931,6 +3932,38 @@ async def widget(self) -> Widget:

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

WidgetStyle = Literal['shield', 'banner1', 'banner2', 'banner3', 'banner4']
Puncher1 marked this conversation as resolved.
Show resolved Hide resolved

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.

Raises
-------
HTTPException
Retrieving the widget image url failed.
Puncher1 marked this conversation as resolved.
Show resolved Hide resolved

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