Class 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()  
    • Field Detail

      • WIDGET_PNG

        public static final java.lang.String WIDGET_PNG
      • WIDGET_URL

        public static final java.lang.String WIDGET_URL
    • Constructor Detail

      • WidgetUtil

        public WidgetUtil()
    • 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 guild
        type - 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 ID
        type - 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 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 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 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
                                                  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 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:
        java.io.UncheckedIOException - If an I/O error occurs
        RateLimitedException - If the request was rate limited, respect the timeout!