Widgets¶
This section documents everything related to widgets — dynamically generated elements which show basic info about your server and invites to join it easily, which can be displayed on websites.
Discord Models¶
Widget¶
- asyncedit
- asyncfetch_invite
- defimage_url
- class disnake.Widget[source]¶
Represents a
Guild
widget.- x == y
Checks if two widgets are the same.
- x != y
Checks if two widgets are not the same.
- str(x)
Returns the widget’s JSON URL.
- channels¶
The publicly accessible voice and stage channels in the guild.
- Type:
List[
WidgetChannel
]
- members¶
The online members in the server. Offline members do not appear in the widget.
Note
Due to a Discord limitation, if this data is available the users will be “anonymized” with linear IDs. Likewise, the number of members retrieved is capped.
- Type:
List[
WidgetMember
]
- await fetch_invite(*, with_counts=True)[source]¶
This function is a coroutine.
Retrieves an
Invite
from the widget’s invite URL. This is the same asClient.fetch_invite()
; the invite code is abstracted away.Changed in version 2.6: This may now return
None
if the widget does not have an attached invite URL.- Parameters:
with_counts (
bool
) – Whether to include count information in the invite. This fills theInvite.approximate_member_count
andInvite.approximate_presence_count
fields.- Returns:
The invite from the widget’s invite URL, if available.
- Return type:
Optional[
Invite
]
- await edit(*, enabled=..., channel=..., reason=None)[source]¶
This function is a coroutine.
Edits the widget.
You must have
manage_guild
permission to do thisNew in version 2.4.
- Parameters:
- Raises:
Forbidden – You do not have permission to edit the widget.
HTTPException – Editing the widget failed.
- image_url(style=<WidgetStyle.shield: 'shield'>)[source]¶
Returns an URL to the widget’s .png image.
New in version 2.5.
- Parameters:
style (
WidgetStyle
) – The widget style.- Returns:
The widget image URL.
- Return type:
WidgetSettings¶
- asyncedit
- class disnake.WidgetSettings[source]¶
Represents a
Guild
’s widget settings.New in version 2.5.
- channel_id¶
The widget channel ID. If set, an invite link for this channel will be generated, which allows users to join the guild from the widget.
- Type:
Optional[
int
]
- property channel[source]¶
The widget channel, if set.
- Type:
Optional[
abc.GuildChannel
]
- await edit(*, enabled=..., channel=..., reason=None)[source]¶
This function is a coroutine.
Edits the widget.
You must have
manage_guild
permission to do this.- Parameters:
enabled (
bool
) – Whether to enable the widget.channel (Optional[
Snowflake
]) – The new widget channel. PassNone
to remove the widget channel. If set, an invite link for this channel will be generated, which allows users to join the guild from the widget.reason (Optional[
str
]) – The reason for editing the widget. Shows up on the audit log.
- Raises:
Forbidden – You do not have permission to edit the widget.
HTTPException – Editing the widget failed.
- Returns:
The new widget settings.
- Return type:
WidgetChannel¶
- class disnake.WidgetChannel[source]¶
Represents a “partial” widget channel.
- x == y
Checks if two partial channels are the same.
- x != y
Checks if two partial channels are not the same.
- hash(x)
Return the partial channel’s hash.
- str(x)
Returns the partial channel’s name.
WidgetMember¶
- class disnake.WidgetMember[source]¶
Represents a “partial” member of the widget’s guild.
- x == y
Checks if two widget members are the same.
- x != y
Checks if two widget members are not the same.
- hash(x)
Return the widget member’s hash.
- str(x)
Returns the widget member’s name.
- discriminator¶
The member’s anonymized discriminator.
Note
This is being phased out by Discord; the username system is moving away from
username#discriminator
to users having a globally unique username. See the help article for details.- Type:
- activity¶
The member’s activity. This generally only has the
name
set.- Type:
Optional[Union[
BaseActivity
,Spotify
]]
- connected_channel¶
Which channel the member is connected to.
- Type:
Optional[
WidgetChannel
]
- property avatar[source]¶
The user’s avatar. The size can be chosen using
Asset.with_size()
, however the format is always static and cannot be changed throughAsset.with_format()
or similar methods.- Type:
Optional[
Asset
]
Enumerations¶
WidgetStyle¶
- class disnake.WidgetStyle[source]¶
Represents the supported widget image styles.
New in version 2.5.
- shield¶
A shield style image with a Discord icon and the online member count.
- banner1¶
A large image with guild icon, name and online member count and a footer.
- banner2¶
A small image with guild icon, name and online member count.
- banner3¶
A large image with guild icon, name and online member count and a footer, with a “Chat Now” label on the right.
- banner4¶
A large image with a large Discord logo, guild icon, name and online member count, with a “Join My Server” label at the bottom.