Package net.dv8tion.jda.api.utils
Class WidgetUtil
- java.lang.Object
-
- net.dv8tion.jda.api.utils.WidgetUtil
-
public class WidgetUtil extends java.lang.Object
The WidgetUtil is a class for interacting with various facets of Discord's guild widgets- Since:
- 3.0
- Author:
- John A. Grosh
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WidgetUtil.BannerType
Represents the available banner types
Each of these has a different appearance:static class
WidgetUtil.Widget
static class
WidgetUtil.WidgetTheme
Represents the color scheme of the widget
These color themes match Discord's dark and light themes
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
WIDGET_HTML
static java.lang.String
WIDGET_PNG
static java.lang.String
WIDGET_URL
-
Constructor Summary
Constructors Constructor Description WidgetUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
getPremadeWidgetHtml(java.lang.String guildId, WidgetUtil.WidgetTheme theme, int width, int height)
Gets the pre-made HTML Widget for the specified guild using the specified settings.static java.lang.String
getPremadeWidgetHtml(Guild guild, WidgetUtil.WidgetTheme theme, int width, int height)
Gets the pre-made HTML Widget for the specified guild using the specified settings.static WidgetUtil.Widget
getWidget(long guildId)
Makes a GET request to get the information for a Guild's widget.static WidgetUtil.Widget
getWidget(java.lang.String guildId)
Makes a GET request to get the information for a Guild's widget.static java.lang.String
getWidgetBanner(java.lang.String guildId, WidgetUtil.BannerType type)
Gets the banner image for the specified guild of the specified type.static java.lang.String
getWidgetBanner(Guild guild, WidgetUtil.BannerType type)
Gets the banner image for the specified guild of the specified type.
-
-
-
Field Detail
-
WIDGET_PNG
public static final java.lang.String WIDGET_PNG
-
WIDGET_URL
public static final java.lang.String WIDGET_URL
-
WIDGET_HTML
public static final java.lang.String WIDGET_HTML
- See Also:
- Constant Field Values
-
-
Method Detail
-
getWidgetBanner
@Nonnull public static java.lang.String getWidgetBanner(@Nonnull Guild guild, @Nonnull WidgetUtil.BannerType type)
Gets the banner image for the specified guild of the specified type.
This banner will only be available if the guild in question has the Widget enabled.- Parameters:
guild
- The guildtype
- The type (visual style) of the banner- Returns:
- A String containing the URL of the banner image
-
getWidgetBanner
@Nonnull public static java.lang.String getWidgetBanner(@Nonnull java.lang.String guildId, @Nonnull WidgetUtil.BannerType type)
Gets the banner image for the specified guild of the specified type.
This banner will only be available if the guild in question has the Widget enabled. Additionally, this method can be used independently of being on the guild in question.- Parameters:
guildId
- the guild IDtype
- The type (visual style) of the banner- Returns:
- A String containing the URL of the banner image
-
getPremadeWidgetHtml
@Nonnull public static java.lang.String getPremadeWidgetHtml(@Nonnull Guild guild, @Nonnull WidgetUtil.WidgetTheme theme, int width, int height)
Gets the pre-made HTML Widget for the specified guild using the specified settings. The widget will only display correctly if the guild in question has the Widget enabled.- Parameters:
guild
- the guildtheme
- the theme, light or darkwidth
- the width of the widgetheight
- the height of the widget- Returns:
- a String containing the pre-made widget with the supplied settings
-
getPremadeWidgetHtml
@Nonnull public static java.lang.String getPremadeWidgetHtml(@Nonnull java.lang.String guildId, @Nonnull WidgetUtil.WidgetTheme theme, int width, int height)
Gets the pre-made HTML Widget for the specified guild using the specified settings. The widget will only display correctly if the guild in question has the Widget enabled. Additionally, this method can be used independently of being on the guild in question.- Parameters:
guildId
- the guild IDtheme
- the theme, light or darkwidth
- the width of the widgetheight
- the height of the widget- Returns:
- a String containing the pre-made widget with the supplied settings
-
getWidget
@Nullable public static WidgetUtil.Widget getWidget(@Nonnull java.lang.String guildId) throws RateLimitedException
Makes a GET request to get the information for a Guild's widget. This widget (if available) contains information about the guild, including the Guild's name, an invite code (if set), a list of voice channels, and a list of online members (plus the voice states of any members in voice channels).This Widget can be obtained from any valid guild ID that has it enabled; no accounts need to be on the server to access this information.
- Parameters:
guildId
- The id of the Guild- Returns:
null
if the provided guild ID is not a valid Discord guild ID
a Widget object with null fields and isAvailable() returning false if the guild ID is valid but the guild in question does not have the widget enabled
a filled-in Widget object if the guild ID is valid and the guild in question has the widget enabled.- Throws:
RateLimitedException
- If the request was rate limited, respect the timeout!java.lang.NumberFormatException
- If the providedguildId
cannot be parsed byLong.parseLong(String)
-
getWidget
@Nullable public static WidgetUtil.Widget getWidget(long guildId) throws RateLimitedException
Makes a GET request to get the information for a Guild's widget. This widget (if available) contains information about the guild, including the Guild's name, an invite code (if set), a list of voice channels, and a list of online members (plus the voice states of any members in voice channels).This Widget can be obtained from any valid guild ID that has it enabled; no accounts need to be on the server to access this information.
- Parameters:
guildId
- The id of the Guild- Returns:
null
if the provided guild ID is not a valid Discord guild ID
a Widget object with null fields and isAvailable() returning false if the guild ID is valid but the guild in question does not have the widget enabled
a filled-in Widget object if the guild ID is valid and the guild in question has the widget enabled.- Throws:
java.io.UncheckedIOException
- If an I/O error occursRateLimitedException
- If the request was rate limited, respect the timeout!
-
-