Class Template
- java.lang.Object
-
- net.dv8tion.jda.api.entities.templates.Template
-
public class Template extends java.lang.Object
Representation of a Discord Guild Template
This class is immutable.- Since:
- 4.3.0
- See Also:
resolve(JDA, String)
,Guild.retrieveTemplates()
-
-
Constructor Summary
Constructors Constructor Description Template(net.dv8tion.jda.internal.JDAImpl api, java.lang.String code, java.lang.String name, java.lang.String description, int uses, User creator, java.time.OffsetDateTime createdAt, java.time.OffsetDateTime updatedAt, TemplateGuild guild, boolean synced)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RestAction<java.lang.Void>
delete()
Deletes this template.boolean
equals(java.lang.Object obj)
java.lang.String
getCode()
The template code.User
getCreator()
The user who created this template.java.lang.String
getDescription()
The template description.TemplateGuild
getGuild()
ATemplate.Guild
object containing information about this template's origin guild.JDA
getJDA()
TheJDA
instance used to create this Template instance.TemplateManager
getManager()
Returns theTemplateManager
for this Template.java.lang.String
getName()
The template name.java.time.OffsetDateTime
getTimeCreated()
Returns creation date of this template.java.time.OffsetDateTime
getTimeUpdated()
Returns the last update date of this template.int
getUses()
How often this template has been used.int
hashCode()
boolean
isSynced()
Whether or not this template is synced.static RestAction<Template>
resolve(JDA api, java.lang.String code)
Retrieves a newTemplate
instance for the given template code.RestAction<Template>
sync()
Syncs this template.java.lang.String
toString()
-
-
-
Constructor Detail
-
Template
public Template(net.dv8tion.jda.internal.JDAImpl api, java.lang.String code, java.lang.String name, java.lang.String description, int uses, User creator, java.time.OffsetDateTime createdAt, java.time.OffsetDateTime updatedAt, TemplateGuild guild, boolean synced)
-
-
Method Detail
-
resolve
@Nonnull public static RestAction<Template> resolve(JDA api, java.lang.String code)
Retrieves a newTemplate
instance for the given template code.Possible
ErrorResponses
include:Unknown Guild Template
The template doesn't exist.
- Parameters:
api
- The JDA instancecode
- A valid template code- Returns:
RestAction
- Type:Template
The Template object- Throws:
java.lang.IllegalArgumentException
-- If the provided code is null or empty
- If the provided code contains a whitespace
- If the provided JDA object is null
-
sync
@Nonnull @CheckReturnValue public RestAction<Template> sync()
Syncs this template.
RequiresMANAGE_SERVER
in the template's guild. Will throw anInsufficientPermissionException
otherwise.- Returns:
RestAction
- Type:Template
The synced Template object- Throws:
java.lang.IllegalStateException
- If the account is not in the template's guildInsufficientPermissionException
- If the account does not haveMANAGE_SERVER
in the template's guild
-
delete
@Nonnull @CheckReturnValue public RestAction<java.lang.Void> delete()
Deletes this template.
RequiresMANAGE_SERVER
in the template's guild. Will throw anInsufficientPermissionException
otherwise.- Returns:
RestAction
- Throws:
java.lang.IllegalStateException
- If the account is not in the template's guildInsufficientPermissionException
- If the account does not haveMANAGE_SERVER
in the template's guild
-
getCode
@Nonnull public java.lang.String getCode()
The template code.- Returns:
- The template code
-
getName
@Nonnull public java.lang.String getName()
The template name.- Returns:
- The template name
-
getDescription
@Nullable public java.lang.String getDescription()
The template description.- Returns:
- The template description
-
getUses
public int getUses()
How often this template has been used.- Returns:
- The uses of this template
-
getCreator
@Nonnull public User getCreator()
The user who created this template.- Returns:
- The user who created this template
-
getTimeCreated
@Nonnull public java.time.OffsetDateTime getTimeCreated()
Returns creation date of this template.- Returns:
- The creation date of this template
-
getTimeUpdated
@Nonnull public java.time.OffsetDateTime getTimeUpdated()
Returns the last update date of this template.
If this template has never been updated, this returns the date of creation.- Returns:
- The last update date of this template
- See Also:
getTimeCreated()
-
getGuild
@Nonnull public TemplateGuild getGuild()
ATemplate.Guild
object containing information about this template's origin guild.- Returns:
- Information about this template's origin guild
- See Also:
TemplateGuild
-
isSynced
public boolean isSynced()
Whether or not this template is synced.- Returns:
- True, if this template matches the current guild structure
-
getManager
@Nonnull public TemplateManager getManager()
Returns theTemplateManager
for this Template.
In the TemplateManager, you can modify the name or description of the template. You modify multiple fields in one request by chaining setters before callingRestAction.queue()
.This is a lazy idempotent getter. The manager is retained after the first call. This getter is not thread-safe and would require guards by the user.
- Returns:
- The TemplateManager of this Template
- Throws:
java.lang.IllegalStateException
- If the account is not in the template's guildInsufficientPermissionException
- If the currently logged in account does not haveMANAGE_SERVER
-
getJDA
@Nonnull public JDA getJDA()
TheJDA
instance used to create this Template instance.- Returns:
- The corresponding JDA instance
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-