Package discord4j.core.object.entity
Class Role
- java.lang.Object
-
- discord4j.core.object.entity.Role
-
- All Implemented Interfaces:
DiscordObject,Entity
public final class Role extends Object implements Entity
A Discord role.- See Also:
- Role Object
-
-
Field Summary
Fields Modifier and Type Field Description static ColorDEFAULT_COLORThe defaultColorof aRole.
-
Constructor Summary
Constructors Constructor Description Role(GatewayDiscordClient gateway, discord4j.discordjson.json.RoleData data, long guildId)Constructs aRolewith an associatedGatewayDiscordClientand Discord data.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Flux<Role>changePosition(int position)Requests to change this role's position.Mono<Void>delete()Requests to delete this role.Mono<Void>delete(String reason)Requests to delete this role while optionally specifying the reason.discord4j.core.spec.RoleEditMonoedit()Requests to edit this role.Mono<Role>edit(discord4j.core.spec.RoleEditSpec spec)Requests to edit this role.Mono<Role>edit(Consumer<? super LegacyRoleEditSpec> spec)Deprecated.useedit(RoleEditSpec)oredit()which offer an immutable approach to build specsbooleanequals(Object obj)GatewayDiscordClientgetClient()Returns theGatewayDiscordClientthat created this object.ColorgetColor()Gets the color assigned to this role.discord4j.discordjson.json.RoleDatagetData()Gets the data of the role.Mono<Guild>getGuild()Requests to retrieve the guild this role is associated to.Mono<Guild>getGuild(EntityRetrievalStrategy retrievalStrategy)Requests to retrieve the guild this role is associated to, using the given retrieval strategy.SnowflakegetGuildId()Gets the ID of the guild this role is associated to.SnowflakegetId()Gets the Snowflake that uniquely identifies this entity.StringgetMention()Gets the raw mention.StringgetName()Gets the role name.PermissionSetgetPermissions()Gets the permissions assigned to this role.Mono<Integer>getPosition()Requests to retrieve the position of the role relative to other roles in the guild.Mono<Integer>getPosition(EntityRetrievalStrategy retrievalStrategy)Requests to retrieve the position of the role relative to other roles in the guild, using the given retrieval strategy.intgetRawPosition()Gets the sorting position of the role.Optional<RoleTags>getTags()Gets the tags this role has, if present.inthashCode()booleanisEveryone()Gets whether this role corresponds to the @everyone role.booleanisHoisted()Gets whether if this role is pinned in the user listing.booleanisManaged()Gets whether this role is managed by an integration.booleanisMentionable()Gets whether this role is mentionable.StringtoString()
-
-
-
Constructor Detail
-
Role
public Role(GatewayDiscordClient gateway, discord4j.discordjson.json.RoleData data, long guildId)
Constructs aRolewith an associatedGatewayDiscordClientand Discord data.- Parameters:
gateway- TheGatewayDiscordClientassociated to this object, must be non-null.data- The raw data as represented by Discord, must be non-null.guildId- The ID of the guild this role is associated to.
-
-
Method Detail
-
getClient
public GatewayDiscordClient getClient()
Description copied from interface:DiscordObjectReturns theGatewayDiscordClientthat created this object. Methods in it are exclusively based on the entity cache orStorein use. Refer to callinggetClient().rest()to access aDiscordClientthat is capable of requesting entities directly from the REST API.- Specified by:
getClientin interfaceDiscordObject- Returns:
- The
GatewayDiscordClientassociated to this object.
-
getData
public discord4j.discordjson.json.RoleData getData()
Gets the data of the role.- Returns:
- The data of the role.
-
getRawPosition
public int getRawPosition()
Gets the sorting position of the role.- Returns:
- The sorting position of the role.
-
getPosition
public Mono<Integer> getPosition()
Requests to retrieve the position of the role relative to other roles in the guild.This is determined by the index of this role in the
sortedlist of roles of the guild.Warning: Because this method must sort the guild roles, it is inefficient to make repeated invocations for the same set of roles (meaning that roles haven't been added or removed). For example, instead of writing:
It would be much more efficient to write:guild.getRoles() .flatMap(r -> r.getPosition().map(pos -> r.getName() + " : " + pos))guild.getRoles() .transform(OrderUtil::orderRoles) .index((pos, r) -> r.getName() + " : " + pos)- Returns:
- A
Monowhere, upon successful completion, emits the position of the role. If an error is received, it is emitted through theMono.
-
getPosition
public Mono<Integer> getPosition(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the position of the role relative to other roles in the guild, using the given retrieval strategy.This is determined by the index of this role in the
sortedlist of roles of the guild.Warning: Because this method must sort the guild roles, it is inefficient to make repeated invocations for the same set of roles (meaning that roles haven't been added or removed). For example, instead of writing:
It would be much more efficient to write:guild.getRoles() .flatMap(r -> r.getPosition().map(pos -> r.getName() + " : " + pos))guild.getRoles() .transform(OrderUtil::orderRoles) .index((pos, r) -> r.getName() + " : " + pos)- Parameters:
retrievalStrategy- the strategy to use to get the guild and the other roles- Returns:
- A
Monowhere, upon successful completion, emits the position of the role. If an error is received, it is emitted through theMono.
-
getName
public String getName()
Gets the role name.- Returns:
- The role name.
-
getColor
public Color getColor()
Gets the color assigned to this role.- Returns:
- The color assigned to this role.
-
isHoisted
public boolean isHoisted()
Gets whether if this role is pinned in the user listing.- Returns:
trueif this role is pinned in the user listing,falseotherwise.
-
getPermissions
public PermissionSet getPermissions()
Gets the permissions assigned to this role.- Returns:
- The permissions assigned to this role.
-
isManaged
public boolean isManaged()
Gets whether this role is managed by an integration.- Returns:
trueif this role is managed by an integration,falseotherwise.
-
isMentionable
public boolean isMentionable()
Gets whether this role is mentionable.- Returns:
trueif this role is mentionable,falseotherwise.
-
isEveryone
public boolean isEveryone()
Gets whether this role corresponds to the @everyone role.- Returns:
trueif this role represents the @everyone role,falseotherwise.
-
getGuildId
public Snowflake getGuildId()
Gets the ID of the guild this role is associated to.- Returns:
- The ID of the guild this role is associated to.
-
getGuild
public Mono<Guild> getGuild(EntityRetrievalStrategy retrievalStrategy)
Requests to retrieve the guild this role is associated to, using the given retrieval strategy.
-
getMention
public String getMention()
Gets the raw mention. This is the format utilized to directly mention another role (assuming the role exists in context of the mention).- Returns:
- The raw mention.
-
getTags
public Optional<RoleTags> getTags()
Gets the tags this role has, if present.- Returns:
- The tags this role has, if present.
-
getId
public Snowflake getId()
Description copied from interface:EntityGets the Snowflake that uniquely identifies this entity.
-
edit
@Deprecated public Mono<Role> edit(Consumer<? super LegacyRoleEditSpec> spec)
Deprecated.useedit(RoleEditSpec)oredit()which offer an immutable approach to build specsRequests to edit this role.- Parameters:
spec- AConsumerthat provides a "blank"LegacyRoleEditSpecto be operated on.- Returns:
- A
Monowhere, upon successful completion, emits the editedRole. If an error is received, it is emitted through theMono.
-
edit
public discord4j.core.spec.RoleEditMono edit()
Requests to edit this role. Properties specifying how to edit this role can be set via thewithXxxmethods of the returnedRoleEditMono.- Returns:
- A
RoleEditMonowhere, upon successful completion, emits the editedRole. If an error is received, it is emitted through theRoleEditMono.
-
delete
public Mono<Void> delete()
Requests to delete this role.- Returns:
- A
Monowhere, upon successful completion, emits nothing; indicating the role has been deleted. If an error is received, it is emitted through theMono.
-
delete
public Mono<Void> delete(@Nullable String reason)
Requests to delete this role while optionally specifying the reason.- Parameters:
reason- The reason, if present.- Returns:
- A
Monowhere, upon successful completion, emits nothing; indicating the role has been deleted. If an error is received, it is emitted through theMono.
-
changePosition
public Flux<Role> changePosition(int position)
Requests to change this role's position.
-
-