Package net.dv8tion.jda.api.entities
Interface Activity
-
- All Known Subinterfaces:
RichPresence
public interface Activity
Represents a DiscordActivity
.
This should contain all information provided from Discord about a Activity.- Since:
- 2.1
- Author:
- John A. Grosh
- See Also:
of(ActivityType, String)
,of(ActivityType, String, String)
,playing(String)
,watching(String)
,listening(String)
,streaming(String, String)
,competing(String)
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Activity.ActivityType
The type game being played, differentiating between a game and stream types.static class
Activity.Emoji
Emoji for a custom status.static class
Activity.Timestamps
Represents the start and end timestamps for a running match
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.Pattern
STREAMING_URL
The Pattern used forisValidStreamingUrl(String)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description RichPresence
asRichPresence()
RichPresence
representation of this Activity.static Activity
competing(java.lang.String name)
Creates a new Activity instance with the specified name.Activity.Emoji
getEmoji()
The emoji (or custom emoji) attached to a custom status.java.lang.String
getName()
The displayed name of theActivity
.Activity.Timestamps
getTimestamps()
Information on the match duration, start, and end.Activity.ActivityType
getType()
The type ofActivity
.java.lang.String
getUrl()
The URL of theActivity
if the game is actually a Stream.boolean
isRich()
static boolean
isValidStreamingUrl(java.lang.String url)
Checks if a given String is a valid Twitch/Youtube streaming url (ie, one that will display "Streaming" on the Discord client).static Activity
listening(java.lang.String name)
Creates a new Activity instance with the specified name.static Activity
of(Activity.ActivityType type, java.lang.String name)
Creates a new Activity instance with the specified name.static Activity
of(Activity.ActivityType type, java.lang.String name, java.lang.String url)
Creates a new Activity instance with the specified name and url.static Activity
playing(java.lang.String name)
Creates a new Activity instance with the specified name.static Activity
streaming(java.lang.String name, java.lang.String url)
Creates a new Activity instance with the specified name and url.static Activity
watching(java.lang.String name)
Creates a new Activity instance with the specified name.
-
-
-
Field Detail
-
STREAMING_URL
static final java.util.regex.Pattern STREAMING_URL
The Pattern used forisValidStreamingUrl(String)
-
-
Method Detail
-
isRich
boolean isRich()
- Returns:
true
if this is aRichPresence
-
asRichPresence
@Nullable RichPresence asRichPresence()
RichPresence
representation of this Activity.- Returns:
- RichPresence or
null
ifisRich()
returnsfalse
-
getName
@Nonnull java.lang.String getName()
The displayed name of theActivity
.
ForActivity.ActivityType.CUSTOM_STATUS
this will return the custom status text.- Returns:
- String containing the Activity's name.
-
getUrl
@Nullable java.lang.String 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
@Nonnull Activity.ActivityType getType()
The type ofActivity
.- Returns:
- Never-null
ActivityType
representing the type of Activity
-
getTimestamps
@Nullable Activity.Timestamps getTimestamps()
Information on the match duration, start, and end.- Returns:
Timestamps
wrapper ofnull
if unset
-
getEmoji
@Nullable Activity.Emoji getEmoji()
The emoji (or custom emoji) attached to a custom status.- Returns:
- Possibly-null
Activity.Emoji
used for custom status
-
playing
@Nonnull static Activity playing(@Nonnull java.lang.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 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.DEFAULT
- Throws:
java.lang.IllegalArgumentException
- if the specified name is null, empty, blank or longer than 128 characters
-
streaming
@Nonnull static Activity streaming(@Nonnull java.lang.String name, @Nullable java.lang.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 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:
java.lang.IllegalArgumentException
- If the specified name is null, empty or longer than 128 characters- See Also:
isValidStreamingUrl(String)
-
listening
@Nonnull static Activity listening(@Nonnull java.lang.String name)
Creates a new Activity instance with the specified name.
This will display asListening 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:
java.lang.IllegalArgumentException
- if the specified name is null, empty, blank or longer than 128 characters
-
watching
@Nonnull @Incubating static Activity watching(@Nonnull java.lang.String name)
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:
java.lang.IllegalArgumentException
- if the specified name is null, empty, blank or longer than 128 characters- Incubating:
- This feature is not yet confirmed for the official bot API
-
competing
@Nonnull static Activity competing(@Nonnull java.lang.String name)
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:
java.lang.IllegalArgumentException
- If the specified name is null, empty, blank or longer than 128 characters- Since:
- 4.2.1
-
of
@Nonnull static Activity of(@Nonnull Activity.ActivityType type, @Nonnull java.lang.String name)
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:
java.lang.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 java.lang.String name, @Nullable java.lang.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 gameurl
- The streaming url to use, required to display as "streaming".- Returns:
- A valid Activity instance with the provided name and url
- Throws:
java.lang.IllegalArgumentException
-- If the specified ActivityType is null or unsupported
- If the specified name is null, empty or longer than 128 characters
- See Also:
isValidStreamingUrl(String)
-
isValidStreamingUrl
static boolean isValidStreamingUrl(@Nullable java.lang.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
-
-