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 Color
DEFAULT_COLOR
The defaultColor
of aRole
.
-
Constructor Summary
Constructors Constructor Description Role(GatewayDiscordClient gateway, discord4j.discordjson.json.RoleData data, long guildId)
Constructs aRole
with an associatedGatewayDiscordClient
and 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.RoleEditMono
edit()
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 specsboolean
equals(Object obj)
GatewayDiscordClient
getClient()
Returns theGatewayDiscordClient
that created this object.Color
getColor()
Gets the color assigned to this role.discord4j.discordjson.json.RoleData
getData()
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.Snowflake
getGuildId()
Gets the ID of the guild this role is associated to.Optional<String>
getIconUrl(Image.Format format)
Gets the icon URL of the role, if present.Snowflake
getId()
Gets the Snowflake that uniquely identifies this entity.String
getMention()
Gets the raw mention.String
getName()
Gets the role name.PermissionSet
getPermissions()
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.int
getRawPosition()
Gets the sorting position of the role.Optional<RoleTags>
getTags()
Gets the tags this role has, if present.Optional<String>
getUnicodeEmoji()
Gets the Unicode Emoji of the role, if present.int
hashCode()
boolean
isEveryone()
Gets whether this role corresponds to the @everyone role.boolean
isHoisted()
Gets whether if this role is pinned in the user listing.boolean
isManaged()
Gets whether this role is managed by an integration.boolean
isMentionable()
Gets whether this role is mentionable.String
toString()
-
-
-
Constructor Detail
-
Role
public Role(GatewayDiscordClient gateway, discord4j.discordjson.json.RoleData data, long guildId)
Constructs aRole
with an associatedGatewayDiscordClient
and Discord data.- Parameters:
gateway
- TheGatewayDiscordClient
associated 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:DiscordObject
Returns theGatewayDiscordClient
that created this object. Methods in it are exclusively based on the entity cache orStore
in use. Refer to callinggetClient().rest()
to access aDiscordClient
that is capable of requesting entities directly from the REST API.- Specified by:
getClient
in interfaceDiscordObject
- Returns:
- The
GatewayDiscordClient
associated 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
sorted
list 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:
guild.getRoles() .flatMap(r -> r.getPosition().map(pos -> r.getName() + " : " + pos))
guild.getRoles() .transform(OrderUtil::orderRoles) .index((pos, r) -> r.getName() + " : " + pos)
- Returns:
- A
Mono
where, 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
sorted
list 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:
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
Mono
where, upon successful completion, emits the position of the role. If an error is received, it is emitted through theMono
.
-
getIconUrl
public Optional<String> getIconUrl(Image.Format format)
Gets the icon URL of the role, if present.- Parameters:
format
- The format for the URL.- Returns:
- The icon URL of the role, if present.
-
getUnicodeEmoji
public Optional<String> getUnicodeEmoji()
Gets the Unicode Emoji of the role, if present.- Returns:
- The Unicode Emoji of the role, if present.
-
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:
true
if this role is pinned in the user listing,false
otherwise.
-
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:
true
if this role is managed by an integration,false
otherwise.
-
isMentionable
public boolean isMentionable()
Gets whether this role is mentionable.- Returns:
true
if this role is mentionable,false
otherwise.
-
isEveryone
public boolean isEveryone()
Gets whether this role corresponds to the @everyone role.- Returns:
true
if this role represents the @everyone role,false
otherwise.
-
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:Entity
Gets 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
- AConsumer
that provides a "blank"LegacyRoleEditSpec
to be operated on.- Returns:
- A
Mono
where, 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 thewithXxx
methods of the returnedRoleEditMono
.- Returns:
- A
RoleEditMono
where, 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
Mono
where, 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
Mono
where, 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.
-
-