Class WidgetUtil

java.lang.Object
net.dv8tion.jda.api.utils.WidgetUtil

public class WidgetUtil extends Object
The WidgetUtil is a class for interacting with various facets of Discord's guild widgets
Since:
3.0
Author:
John A. Grosh
  • Field Details

  • Constructor Details

    • WidgetUtil

      public WidgetUtil()
  • Method Details

    • getWidgetBanner

      @Nonnull public static 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 guild
      type - The type (visual style) of the banner
      Returns:
      A String containing the URL of the banner image
    • getWidgetBanner

      @Nonnull public static String getWidgetBanner(@Nonnull 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 ID
      type - The type (visual style) of the banner
      Returns:
      A String containing the URL of the banner image
    • getPremadeWidgetHtml

      @Nonnull public static 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 guild
      theme - the theme, light or dark
      width - the width of the widget
      height - the height of the widget
      Returns:
      a String containing the pre-made widget with the supplied settings
    • getPremadeWidgetHtml

      @Nonnull public static String getPremadeWidgetHtml(@Nonnull 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 ID
      theme - the theme, light or dark
      width - the width of the widget
      height - 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 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!
      NumberFormatException - If the provided guildId cannot be parsed by Long.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:
      UncheckedIOException - If an I/O error occurs
      RateLimitedException - If the request was rate limited, respect the timeout!