Package discord4j.core.object.entity
Class Role
java.lang.Object
discord4j.core.object.entity.Role
- All Implemented Interfaces:
DiscordObject
,Entity
A Discord role.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionRole
(GatewayDiscordClient gateway, discord4j.discordjson.json.RoleData data, long guildId) Constructs aRole
with an associatedGatewayDiscordClient
and Discord data. -
Method Summary
Modifier and TypeMethodDescriptionchangePosition
(int position) Requests to change this role's position.delete()
Requests to delete this role.Requests to delete this role while optionally specifying the reason.discord4j.core.spec.RoleEditMono
edit()
Requests to edit this role.edit
(discord4j.core.spec.RoleEditSpec spec) Requests to edit this role.edit
(Consumer<? super LegacyRoleEditSpec> spec) Deprecated.boolean
Returns theGatewayDiscordClient
that created this object.getColor()
Gets the color assigned to this role.discord4j.discordjson.json.RoleData
getData()
Gets the data of the role.getGuild()
Requests to retrieve the guild this role is associated to.getGuild
(EntityRetrievalStrategy retrievalStrategy) Requests to retrieve the guild this role is associated to, using the given retrieval strategy.Gets the ID of the guild this role is associated to.getIconUrl
(Image.Format format) Gets the icon URL of the role, if present.getId()
Gets the Snowflake that uniquely identifies this entity.Gets the raw mention.getName()
Gets the role name.Gets the permissions assigned to this role.Requests to retrieve the position of the role relative to other roles in the guild.getPosition
(EntityRetrievalStrategy retrievalStrategy) Requests to retrieve the position of the role relative to other roles in the guild, using the given retrieval strategy.int
Gets the sorting position of the role.getTags()
Gets the tags this role has, if present.Gets the Unicode Emoji of the role, if present.int
hashCode()
boolean
Gets whether this role corresponds to the @everyone role.boolean
Gets whether if this role is pinned in the user listing.boolean
Gets whether this role is managed by an integration.boolean
Gets whether this role is mentionable.toString()
-
Field Details
-
DEFAULT_COLOR
The defaultColor
of aRole
.
-
-
Constructor Details
-
Role
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 Details
-
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
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
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
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
Gets the Unicode Emoji of the role, if present.- Returns:
- The Unicode Emoji of the role, if present.
-
getName
Gets the role name.- Returns:
- The role name.
-
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
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
Gets the ID of the guild this role is associated to.- Returns:
- The ID of the guild this role is associated to.
-
getGuild
Requests to retrieve the guild this role is associated to. -
getGuild
Requests to retrieve the guild this role is associated to, using the given retrieval strategy. -
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
Gets the tags this role has, if present.- Returns:
- The tags this role has, if present.
-
getId
Description copied from interface:Entity
Gets the Snowflake that uniquely identifies this entity. -
edit
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
.
-
edit
Requests to edit this role. -
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
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
Requests to change this role's position. -
equals
-
hashCode
public int hashCode() -
toString
-
edit(RoleEditSpec)
oredit()
which offer an immutable approach to build specs