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
Guildwidget.- 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:
- 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:
- await fetch_invite(*, with_counts=True)[source]¶
This function is a coroutine.
Retrieves an
Invitefrom 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
Noneif 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_countandInvite.approximate_presence_countfields.- Returns:
The invite from the widget’s invite URL, if available.
- Return type:
- await edit(*, enabled=..., channel=..., reason=None)[source]¶
This function is a coroutine.
Edits the widget.
You must have
manage_guildpermission 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)[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.
- await edit(*, enabled=..., channel=..., reason=None)[source]¶
This function is a coroutine.
Edits the widget.
You must have
manage_guildpermission to do this.- Parameters:
enabled (
bool) – Whether to enable the widget.channel (
Snowflake|None) – The new widget channel. PassNoneto 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 (
str|None) – 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#discriminatorto users having a globally unique username. See the help article for details.- Type:
- activity¶
The member’s activity. This generally only has the
nameset.- Type:
BaseActivity|Spotify|None
- connected_channel¶
Which channel the member is connected to.
- Type:
- 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.
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.