Interface Activity

All Known Subinterfaces:
RichPresence

public interface Activity
Represents a Discord Activity.
This should contain all information provided from Discord about a Activity.
Since:
2.1
Author:
John A. Grosh
See Also:
  • Field Details

  • Method Details

    • isRich

      boolean isRich()
      Whether this is a Rich Presence
      If false the result of asRichPresence() is null
      Returns:
      true if this is a RichPresence
    • asRichPresence

      @Nullable RichPresence asRichPresence()
      RichPresence representation of this Activity.
      Returns:
      RichPresence or null if isRich() returns false
    • getName

      @Nonnull String getName()
      The displayed name of the Activity.
      For Activity.ActivityType.CUSTOM_STATUS this will return the custom status text.
      Returns:
      String containing the Activity's name.
    • getState

      @Nullable String getState()
      The user's activity state
      Example: "Looking to Play", "Playing Solo", "In a Group"

      This shows below the normal activity information in the profile.

      Example
      Code:

      
       Activity.playing("Trivia")
           .withState("Question 20")
       
      Display:
       Playing Trivia
       Question 20
       
      Returns:
      The user's current party status
    • getUrl

      @Nullable String getUrl()
      The URL of the Activity if the game is actually a Stream.
      This will return null for regular games.
      Returns:
      Possibly-null String containing the Activity's URL.
    • getType

      The type of Activity.
      Returns:
      Never-null ActivityType representing the type of Activity
    • getTimestamps

      Information on the match duration, start, and end.
      Returns:
      Timestamps wrapper of null if unset
    • getEmoji

      @Nullable EmojiUnion getEmoji()
      The emoji (or custom emoji) attached to a custom status.
      Returns:
      Possibly-null Emoji used for custom status
    • withState

      @Nonnull @Contract("_->new") Activity withState(@Nullable String state)
      Adds the provided state to the activity.
      The state is shown below the activity, unless it is a custom status.
      Parameters:
      state - The activity state, or null to unset
      Returns:
      New activity instance with the provided state
      Throws:
      IllegalArgumentException - If the state is longer than 128 characters
    • playing

      @Nonnull static Activity playing(@Nonnull String name)
      Creates a new Activity instance with the specified name.
      In order to appear as "streaming" in the official client you must provide a valid (see documentation of method) streaming URL in Activity.streaming(String, String).
      Parameters:
      name - The not-null name of the newly created game
      Returns:
      A valid Activity instance with the provided name with Activity.ActivityType.PLAYING
      Throws:
      IllegalArgumentException - if the specified name is null, empty, blank or longer than 128 characters
    • streaming

      @Nonnull static Activity streaming(@Nonnull String name, @Nullable String url)
      Creates a new Activity instance with the specified name and url.
      The specified URL must be valid according to discord standards in order to display as "streaming" in the official client. A valid streaming URL must be derived from https://twitch.tv/ or https://youtube.com/watch?v= and can be verified using isValidStreamingUrl(String). (see documentation)
      Parameters:
      name - The not-null name of the newly created game
      url - The streaming url to use, required to display as "streaming"
      Returns:
      A valid Activity instance with the provided name and url
      Throws:
      IllegalArgumentException - If the specified name is null, empty or longer than 128 characters
      See Also:
    • listening

      @Nonnull static Activity listening(@Nonnull String name)
      Creates a new Activity instance with the specified name.
      This will display as Listening to name in the official client
      Parameters:
      name - The not-null name of the newly created game
      Returns:
      A valid Activity instance with the provided name with Activity.ActivityType.LISTENING
      Throws:
      IllegalArgumentException - if the specified name is null, empty, blank or longer than 128 characters
    • watching

      @Nonnull static Activity watching(@Nonnull String name)
      Creates a new Activity instance with the specified name.
      This will display as Watching name in the official client
      Parameters:
      name - The not-null name of the newly created game
      Returns:
      A valid Activity instance with the provided name with Activity.ActivityType.WATCHING
      Throws:
      IllegalArgumentException - if the specified name is null, empty, blank or longer than 128 characters
    • competing

      @Nonnull static Activity competing(@Nonnull String name)
      Creates a new Activity instance with the specified name.
      This will display as Competing in name in the official client
      Parameters:
      name - The not-null name of the newly created game
      Returns:
      A valid Activity instance with the provided name with Activity.ActivityType.COMPETING
      Throws:
      IllegalArgumentException - If the specified name is null, empty, blank or longer than 128 characters
      Since:
      4.2.1
    • customStatus

      @Nonnull static Activity customStatus(@Nonnull String name)
      Creates a new Activity instance with the specified name.
      This will display without a prefix in the official client
      Parameters:
      name - The not-null name of the newly created status
      Returns:
      A valid Activity instance with the provided name with Activity.ActivityType.CUSTOM_STATUS
      Throws:
      IllegalArgumentException - If the specified name is null, empty, blank or longer than 128 characters
    • of

      Creates a new Activity instance with the specified name.
      Parameters:
      type - The ActivityType to use
      name - The not-null name of the newly created game
      Returns:
      A valid Activity instance with the provided name
      Throws:
      IllegalArgumentException -
      • If the specified ActivityType is null or unsupported
      • If the specified name is null, empty or longer than 128 characters
    • of

      Creates a new Activity instance with the specified name and url.
      The provided url would only be used for ActivityType.STREAMING and should be a twitch url.
      Parameters:
      type - The ActivityType to use
      name - The not-null name of the newly created game or custom status text
      url - The streaming url to use, required to display as "streaming".
      Returns:
      A valid Activity instance with the provided name and url
      Throws:
      IllegalArgumentException -
      • If the specified ActivityType is null or unsupported
      • If the specified name is null, empty or longer than 128 characters
      See Also:
    • isValidStreamingUrl

      static boolean isValidStreamingUrl(@Nullable String url)
      Checks if a given String is a valid Twitch/Youtube streaming url (ie, one that will display "Streaming" on the Discord client).
      Parameters:
      url - The url to check.
      Returns:
      True if the provided url is valid for triggering Discord's streaming status