Package net.dv8tion.jda.api.entities
Interface Activity
- All Known Subinterfaces:
RichPresence
public interface Activity
Represents a Discord
This should contain all information provided from Discord about a Activity.
Activity.
This should contain all information provided from Discord about a Activity.
- Since:
- 2.1
- Author:
- John A. Grosh
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumThe activity being executed, differentiating between, amongst others, playing, listening and streaming.static classRepresents the start and end timestamps for a running match -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum length for an activity namestatic final intMaximum length for an activity statestatic final PatternThe Pattern used forisValidStreamingUrl(String) -
Method Summary
Modifier and TypeMethodDescriptionRichPresencerepresentation of this Activity.static ActivityCreates a new Activity instance with the specified name.static ActivitycustomStatus(String name) Creates a new Activity instance with the specified name.getEmoji()The emoji (or custom emoji) attached to a custom status.getName()The displayed name of theActivity.getState()The user's activity state
Example: "Looking to Play", "Playing Solo", "In a Group"Information on the match duration, start, and end.getType()The type ofActivity.getUrl()The URL of theActivityif the game is actually a Stream.booleanisRich()static booleanChecks if a given String is a valid Twitch/Youtube streaming url (ie, one that will display "Streaming" on the Discord client).static ActivityCreates a new Activity instance with the specified name.static Activityof(Activity.ActivityType type, String name) Creates a new Activity instance with the specified name.static Activityof(Activity.ActivityType type, String name, String url) Creates a new Activity instance with the specified name and url.static ActivityCreates a new Activity instance with the specified name.static ActivityCreates a new Activity instance with the specified name and url.static ActivityCreates a new Activity instance with the specified name.Adds the provided state to the activity.
-
Field Details
-
STREAMING_URL
The Pattern used forisValidStreamingUrl(String) -
MAX_ACTIVITY_NAME_LENGTH
static final int MAX_ACTIVITY_NAME_LENGTHMaximum length for an activity name- See Also:
-
MAX_ACTIVITY_STATE_LENGTH
static final int MAX_ACTIVITY_STATE_LENGTHMaximum length for an activity state- See Also:
-
-
Method Details
-
isRich
boolean isRich()- Returns:
trueif this is aRichPresence
-
asRichPresence
RichPresencerepresentation of this Activity.- Returns:
- RichPresence or
nullifisRich()returnsfalse
-
getName
The displayed name of theActivity.
ForActivity.ActivityType.CUSTOM_STATUSthis will return the custom status text.- Returns:
- String containing the Activity's name.
-
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:
Display:Activity.playing("Trivia") .withState("Question 20")Playing Trivia Question 20
- Returns:
- The user's current party status
-
getUrl
The URL of theActivityif 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 ofActivity.- Returns:
- Never-null
ActivityTyperepresenting the type of Activity
-
getTimestamps
Information on the match duration, start, and end.- Returns:
Timestampswrapper ofnullif unset
-
getEmoji
The emoji (or custom emoji) attached to a custom status.- Returns:
- Possibly-null
Emojiused for custom status
-
withState
Adds the provided state to the activity.
The state is shown below the activity, unless it is acustom 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
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 inActivity.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
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 fromhttps://twitch.tv/orhttps://youtube.com/watch?v=and can be verified usingisValidStreamingUrl(String). (see documentation)- Parameters:
name- The not-null name of the newly created gameurl- 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
Creates a new Activity instance with the specified name.
This will display asListening to namein 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
Creates a new Activity instance with the specified name.
This will display asWatching namein 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
Creates a new Activity instance with the specified name.
This will display asCompeting in namein 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
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- TheActivityTypeto usename- 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
@Nonnull static Activity of(@Nonnull Activity.ActivityType type, @Nonnull String name, @Nullable String url) Creates a new Activity instance with the specified name and url.
The provided url would only be used forActivityType.STREAMINGand should be a twitch url.- Parameters:
type- TheActivityTypeto usename- The not-null name of the newly created game or custom status texturl- 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
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
-