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
Modifier and TypeInterfaceDescriptionstatic enum
The activity being executed, differentiating between, amongst others, playing, listening and streaming.static class
Represents the start and end timestamps for a running match -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Maximum length for an activity namestatic final int
Maximum length for an activity statestatic final Pattern
The Pattern used forisValidStreamingUrl(String)
-
Method Summary
Modifier and TypeMethodDescriptionRichPresence
representation of this Activity.static Activity
Creates a new Activity instance with the specified name.static Activity
customStatus
(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 theActivity
if the game is actually a Stream.boolean
isRich()
static boolean
Checks if a given String is a valid Twitch/Youtube streaming url (ie, one that will display "Streaming" on the Discord client).static Activity
Creates a new Activity instance with the specified name.static Activity
of
(Activity.ActivityType type, String name) Creates a new Activity instance with the specified name.static Activity
of
(Activity.ActivityType type, String name, String url) Creates a new Activity instance with the specified name and url.static Activity
Creates a new Activity instance with the specified name.static Activity
Creates a new Activity instance with the specified name and url.static Activity
Creates 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:
true
if this is aRichPresence
-
asRichPresence
RichPresence
representation of this Activity.- Returns:
- RichPresence or
null
ifisRich()
returnsfalse
-
getName
The displayed name of theActivity
.
ForActivity.ActivityType.CUSTOM_STATUS
this 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 theActivity
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 ofActivity
.- Returns:
- Never-null
ActivityType
representing the type of Activity
-
getTimestamps
Information on the match duration, start, and end.- Returns:
Timestamps
wrapper ofnull
if unset
-
getEmoji
The emoji (or custom emoji) attached to a custom status.- Returns:
- Possibly-null
Emoji
used 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 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
Creates a new Activity instance with the specified name.
This will display asWatching 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
Creates a new Activity instance with the specified name.
This will display asCompeting 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
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
- TheActivityType
to 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.STREAMING
and should be a twitch url.- Parameters:
type
- TheActivityType
to 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
-