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:
  • Field Details

    • DEFAULT_COLOR

      public static final Color DEFAULT_COLOR
      The default Color of a Role.
  • Constructor Details

    • Role

      public Role(GatewayDiscordClient gateway, discord4j.discordjson.json.RoleData data, long guildId)
      Constructs a Role with an associated GatewayDiscordClient and Discord data.
      Parameters:
      gateway - The GatewayDiscordClient 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

      public GatewayDiscordClient getClient()
      Description copied from interface: DiscordObject
      Returns the GatewayDiscordClient that created this object. Methods in it are exclusively based on the entity cache or Store in use. Refer to calling getClient().rest() to access a DiscordClient that is capable of requesting entities directly from the REST API.
      Specified by:
      getClient in interface DiscordObject
      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))
       
       
      It would be much more efficient to write:
       
       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 the Mono.
    • 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))
       
       
      It would be much more efficient to write:
       
       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 the Mono.
    • 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()
      Requests to retrieve the guild this role is associated to.
      Returns:
      A Mono where, upon successful completion, emits the guild this role is associated to. If an error is received, it is emitted through the Mono.
    • getGuild

      public Mono<Guild> getGuild(EntityRetrievalStrategy retrievalStrategy)
      Requests to retrieve the guild this role is associated to, using the given retrieval strategy.
      Parameters:
      retrievalStrategy - the strategy to use to get the guild
      Returns:
      A Mono where, upon successful completion, emits the guild this role is associated to. If an error is received, it is emitted through the Mono.
    • 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.
    • getFlags

      public EnumSet<Role.Flag> getFlags()
      Returns the flags of this Role.
      Returns:
      A EnumSet with the flags of this role.
    • getId

      public Snowflake getId()
      Description copied from interface: Entity
      Gets the Snowflake that uniquely identifies this entity.
      Specified by:
      getId in interface Entity
      Returns:
      The Snowflake that uniquely identifies this entity.
    • edit

      @Deprecated public Mono<Role> edit(Consumer<? super LegacyRoleEditSpec> spec)
      Deprecated.
      use edit(RoleEditSpec) or edit() which offer an immutable approach to build specs
      Requests to edit this role.
      Parameters:
      spec - A Consumer that provides a "blank" LegacyRoleEditSpec to be operated on.
      Returns:
      A Mono where, upon successful completion, emits the edited Role. If an error is received, it is emitted through the Mono.
    • edit

      public discord4j.core.spec.RoleEditMono edit()
      Requests to edit this role. Properties specifying how to edit this role can be set via the withXxx methods of the returned RoleEditMono.
      Returns:
      A RoleEditMono where, upon successful completion, emits the edited Role. If an error is received, it is emitted through the RoleEditMono.
    • edit

      public Mono<Role> edit(discord4j.core.spec.RoleEditSpec spec)
      Requests to edit this role.
      Parameters:
      spec - an immutable object that specifies how to edit this role
      Returns:
      A Mono where, upon successful completion, emits the edited Role. If an error is received, it is emitted through the Mono.
    • 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 the Mono.
    • 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 the Mono.
    • changePosition

      public Flux<Role> changePosition(int position)
      Requests to change this role's position.
      Parameters:
      position - The position to change for this role.
      Returns:
      A Flux that continually emits all the roles associated to this role's guild. If an error is received, it is emitted through the Flux.
    • equals

      public boolean equals(@Nullable Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object