Interface Role
-
- All Superinterfaces:
java.lang.Comparable<Role>,Deletable,DiscordEntity,java.util.Formattable,Mentionable,Nameable,Permissionable,RoleAttachableListenerManager,Updatable<Role>,UpdatableFromCache<Role>
public interface Role extends DiscordEntity, Mentionable, Nameable, Deletable, Permissionable, java.lang.Comparable<Role>, UpdatableFromCache<Role>, RoleAttachableListenerManager
This class represents a Discord role, e.g. "moderator".
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.util.concurrent.CompletableFuture<java.lang.Void>addUser(User user)Adds the role to the given user.default java.util.concurrent.CompletableFuture<java.lang.Void>addUser(User user, java.lang.String reason)Adds the role to the given user.default RoleUpdatercreateUpdater()Gets the updater for this role.default java.util.Set<PermissionType>getAllowedPermissions()Gets the allowed permissions of the role.java.util.Optional<java.awt.Color>getColor()Gets the color of the role.default java.util.Optional<Role>getCurrentCachedInstance()Gets an updated instance of this entity from the cache.java.util.Optional<Icon>getIcon()Gets the Icon of the role.java.util.Optional<Icon>getIcon(int size)Gets the Icon of the role.java.util.Optional<java.lang.String>getIconHash()Gets the hash of the role's icon.default java.lang.StringgetMentionTag()Gets the tag used to mention the entity.PermissionsgetPermissions()Gets the permissions of the role.default intgetPosition()Gets the real position of the role.intgetRawPosition()Gets the raw position of the role.java.util.Optional<RoleTags>getRoleTags()Gets the role tags of the role.ServergetServer()Gets the server of the role.java.util.Optional<java.lang.String>getUnicodeEmojiIcon()Gets the unicode emoji role icon.default java.util.Set<PermissionType>getUnsetPermissions()Gets the unset permissions of the role.java.util.Set<User>getUsers()Gets all users who have this role.booleanhasUser(User user)Checks whether the specified user has this role.booleanisDisplayedSeparately()Check if this role is pinned in the user listing (sometimes called "hoist").default booleanisEveryoneRole()Checks if the role is the @everyone role.booleanisManaged()Checks if this role is managed by an integration.booleanisMentionable()Check if this role is mentionable.default java.util.concurrent.CompletableFuture<java.lang.Void>removeUser(User user)Removes the role from the given user.default java.util.concurrent.CompletableFuture<java.lang.Void>removeUser(User user, java.lang.String reason)Removes the role from the given user.default java.util.concurrent.CompletableFuture<java.lang.Void>updateColor(java.awt.Color color)Updates the color of the role.default java.util.concurrent.CompletableFuture<java.lang.Void>updateDisplaySeparatelyFlag(boolean displaySeparately)Updates the display separately flag of the role.default java.util.concurrent.CompletableFuture<java.lang.Void>updateMentionableFlag(boolean mentionable)Updates the mentionable flag of the role.default java.util.concurrent.CompletableFuture<java.lang.Void>updateName(java.lang.String name)Updates the name of the role.default java.util.concurrent.CompletableFuture<java.lang.Void>updatePermissions(Permissions permissions)Updates the permissions of the role.-
Methods inherited from interface org.javacord.api.entity.Deletable
delete, delete, deleteAfter, deleteAfter, deleteAfter, deleteAfter, getApi
-
Methods inherited from interface org.javacord.api.entity.DiscordEntity
getApi, getCreationTimestamp, getId, getIdAsString
-
Methods inherited from interface org.javacord.api.listener.server.role.RoleAttachableListenerManager
addRoleAttachableListener, addRoleChangeColorListener, addRoleChangeHoistListener, addRoleChangeMentionableListener, addRoleChangeNameListener, addRoleChangePermissionsListener, addRoleChangePositionListener, addRoleDeleteListener, addServerChannelChangeOverwrittenPermissionsListener, addUserRoleAddListener, addUserRoleRemoveListener, getRoleAttachableListeners, getRoleChangeColorListeners, getRoleChangeHoistListeners, getRoleChangeMentionableListeners, getRoleChangeNameListeners, getRoleChangePermissionsListeners, getRoleChangePositionListeners, getRoleDeleteListeners, getServerChannelChangeOverwrittenPermissionsListeners, getUserRoleAddListeners, getUserRoleRemoveListeners, removeListener, removeRoleAttachableListener
-
Methods inherited from interface org.javacord.api.entity.UpdatableFromCache
getLatestInstance
-
-
-
-
Method Detail
-
getServer
Server getServer()
Gets the server of the role.- Returns:
- The server of the role.
-
getRoleTags
java.util.Optional<RoleTags> getRoleTags()
Gets the role tags of the role.- Returns:
- The role tags of the role.
-
getPosition
default int getPosition()
Gets the real position of the role.Will return
-1if the Role got deleted.- Returns:
- The real position of the role.
-
getRawPosition
int getRawPosition()
Gets the raw position of the role.This is the position that gets send by discord. It might not be unique and there might be a gap between roles.
- Returns:
- The raw position of the role.
-
getColor
java.util.Optional<java.awt.Color> getColor()
Gets the color of the role.- Returns:
- The color of the role.
-
getIconHash
java.util.Optional<java.lang.String> getIconHash()
Gets the hash of the role's icon.- Returns:
- The hash of the role's icon.
-
getIcon
java.util.Optional<Icon> getIcon()
Gets the Icon of the role.- Returns:
- The role's icon.
-
getIcon
java.util.Optional<Icon> getIcon(int size)
Gets the Icon of the role.- Parameters:
size- The size of the image, must be a power of 2 between 16 and 4096.- Returns:
- The role's icon in the given size.
-
getUnicodeEmojiIcon
java.util.Optional<java.lang.String> getUnicodeEmojiIcon()
Gets the unicode emoji role icon.- Returns:
- The unicode emoji role icon.
-
isMentionable
boolean isMentionable()
Check if this role is mentionable.- Returns:
- Whether this role is mentionable or not.
-
isDisplayedSeparately
boolean isDisplayedSeparately()
Check if this role is pinned in the user listing (sometimes called "hoist").- Returns:
- Whether this role is pinned in the user listing or not.
-
getUsers
java.util.Set<User> getUsers()
Gets all users who have this role.- Returns:
- All users who have this role.
-
hasUser
boolean hasUser(User user)
Checks whether the specified user has this role.- Parameters:
user- the user to check- Returns:
- true if the user has this role; false otherwise
-
getPermissions
Permissions getPermissions()
Gets the permissions of the role.- Returns:
- The permissions of the role.
-
isManaged
boolean isManaged()
Checks if this role is managed by an integration.- Returns:
- Whether this role is managed by an integration or not.
-
isEveryoneRole
default boolean isEveryoneRole()
Checks if the role is the @everyone role.- Returns:
- Whether the role is the @everyone role or not.
-
createUpdater
default RoleUpdater createUpdater()
Gets the updater for this role.- Returns:
- The updater for this role.
-
updateName
default java.util.concurrent.CompletableFuture<java.lang.Void> updateName(java.lang.String name)
Updates the name of the role.If you want to update several settings at once, it's recommended to use the
RoleUpdaterfromcreateUpdater()which provides a better performance!- Parameters:
name- The new name of the role.- Returns:
- A future to check if the update was successful.
-
updatePermissions
default java.util.concurrent.CompletableFuture<java.lang.Void> updatePermissions(Permissions permissions)
Updates the permissions of the role.If you want to update several settings at once, it's recommended to use the
RoleUpdaterfromcreateUpdater()which provides a better performance!- Parameters:
permissions- The new permissions of the role.- Returns:
- A future to check if the update was successful.
-
updateColor
default java.util.concurrent.CompletableFuture<java.lang.Void> updateColor(java.awt.Color color)
Updates the color of the role.If you want to update several settings at once, it's recommended to use the
RoleUpdaterfromcreateUpdater()which provides a better performance!- Parameters:
color- The new color of the role.- Returns:
- A future to check if the update was successful.
-
updateDisplaySeparatelyFlag
default java.util.concurrent.CompletableFuture<java.lang.Void> updateDisplaySeparatelyFlag(boolean displaySeparately)
Updates the display separately flag of the role.If you want to update several settings at once, it's recommended to use the
RoleUpdaterfromcreateUpdater()which provides a better performance!- Parameters:
displaySeparately- The new display separately flag of the role.- Returns:
- A future to check if the update was successful.
-
updateMentionableFlag
default java.util.concurrent.CompletableFuture<java.lang.Void> updateMentionableFlag(boolean mentionable)
Updates the mentionable flag of the role.If you want to update several settings at once, it's recommended to use the
RoleUpdaterfromcreateUpdater()which provides a better performance!- Parameters:
mentionable- The new mentionable flag of the role.- Returns:
- A future to check if the update was successful.
-
addUser
default java.util.concurrent.CompletableFuture<java.lang.Void> addUser(User user)
Adds the role to the given user.If you want to update several settings at once, it's recommended to use the
ServerUpdaterfromServer.createUpdater()which provides a better performance!- Parameters:
user- The user the role should be added to.- Returns:
- A future to check if the update was successful.
- See Also:
Server.addRoleToUser(User, Role)
-
addUser
default java.util.concurrent.CompletableFuture<java.lang.Void> addUser(User user, java.lang.String reason)
Adds the role to the given user.If you want to update several settings at once, it's recommended to use the
ServerUpdaterfromServer.createUpdater()which provides a better performance!- Parameters:
user- The user the role should be added to.reason- The audit log reason for this update.- Returns:
- A future to check if the update was successful.
- See Also:
Server.addRoleToUser(User, Role, String)
-
removeUser
default java.util.concurrent.CompletableFuture<java.lang.Void> removeUser(User user)
Removes the role from the given user.If you want to update several settings at once, it's recommended to use the
ServerUpdaterfromServer.createUpdater()which provides a better performance!- Parameters:
user- The user the role should be removed from.- Returns:
- A future to check if the update was successful.
- See Also:
Server.removeRoleFromUser(User, Role)
-
removeUser
default java.util.concurrent.CompletableFuture<java.lang.Void> removeUser(User user, java.lang.String reason)
Removes the role from the given user.If you want to update several settings at once, it's recommended to use the
ServerUpdaterfromServer.createUpdater()which provides a better performance!- Parameters:
user- The user the role should be removed from.reason- The audit log reason for this update.- Returns:
- A future to check if the update was successful.
- See Also:
Server.removeRoleFromUser(User, Role, String)
-
getAllowedPermissions
default java.util.Set<PermissionType> getAllowedPermissions()
Gets the allowed permissions of the role.- Returns:
- The allowed permissions of the role.
-
getUnsetPermissions
default java.util.Set<PermissionType> getUnsetPermissions()
Gets the unset permissions of the role.- Returns:
- The unset permissions of the role.
-
getMentionTag
default java.lang.String getMentionTag()
Description copied from interface:MentionableGets the tag used to mention the entity.- Specified by:
getMentionTagin interfaceMentionable- Returns:
- The tag used to mention the entity.
-
getCurrentCachedInstance
default java.util.Optional<Role> getCurrentCachedInstance()
Description copied from interface:UpdatableFromCacheGets an updated instance of this entity from the cache. This is for example necessary if an instance got invalid by a reconnect to Discord which invalidates all existing instances which means they do not get any further updates from Discord applied. Due to that, references to instances should usually not be held for an extended period of time. If they are, this method can be used to retrieve the current instance from the cache, that gets updates from Discord, in case this one was invalidated.This method returns the currently cached entity, or an empty
Optionalif the entity is not cached any longer, for example because it was deleted or the message was thrown out of the cache.- Specified by:
getCurrentCachedInstancein interfaceUpdatableFromCache<Role>- Returns:
- The current cached instance.
-
-