Role
Represents a Discord guild's role.
Attributes color :
The role's color. If the color equals to Color(0)
, then it is ignored meanwhile calculating towards a user's display color.
The role flags.
int
The role's guild's identifier.
int
The guild's icon's hash in uint128
.
Mutually exclusive with .unicode_emoji
The guild's icon's type.
Mutually exclusive with .unicode_emoji
int
The unique identifier number of the role.
If the role is managed, then it's manager's metadata.
If the role is managed, defines by what it is.
bool
Whether the role can be mentioned.
str
The name of the role. Can be empty string, if the role has no known name.
The permissions of the users having the role.
int
The role's position.
bool
Users show up in separated groups by their highest separated
role.
None
, Emoji
Unicode emoji icon of the role.
Mutually exclusive with .icon_hash
and .icon_type
.
Properties
created_at
When the entity was created.
Returns
created_at : datetime
guild
icon
icon_url
Returns the role's icon's image's url. If the role has no icon, then returns None
.
This function is a shared property of Role
-s.
Returns
url : None
, str
managed
Returns whether the role is managed.
Returns
managed: bool
manager
Returns the entity's identifier to which the role is managed by.
Returns
manager : None
, ClientUserBase
, Integration
manager_id
Returns the entity's identifier to which the role is managed by.
Returns
manager_id : int
mention
The role's mention.
Returns
mention : str
partial
Returns whether the role is partial.
Partial roles have .guild
set as None
.
Returns
partial : bool
users
Methods
(...)
__new__Creates a new partial role from the given fields.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
color |
| The role's color. | ||
flags |
| The role's flags. | ||
icon |
| The role's icon.
| ||
manager |
| The role's manager. | ||
mentionable |
| Whether the role can be mentioned. | ||
name |
| The role's name. | ||
permissions |
| The permissions of the users having the role. | ||
position |
| The role's position. | ||
separated |
| Users show up in separated groups by their highest | ||
unicode_emoji |
| The role's icon as an unicode emoji.
|
Returns
self : instance<cls>
Raises
TypeError
- Value of invalid type given.
ValueError
- Value of invalid value given.
icon
andunicode_emoji
are mutually exclusive.
()
copyCopies the role returning a new partial one.
Returns
new : instance<cls>
(...)
copy_withCopies the role with modifying its defined fields, returning a new partial one.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
color |
| The role's color. | ||
flags |
| The role's flags. | ||
icon |
| The role's icon.
| ||
manager |
| The role's manager. | ||
mentionable |
| Whether the role can be mentioned. | ||
name |
| The role's name. | ||
permissions |
| The permissions of the users having the role. | ||
position |
| The role's position. | ||
separated |
| Users show up in separated groups by their highest | ||
unicode_emoji |
| The role's icon as an unicode emoji.
|
Returns
new : instance<type<self>>
Raises
TypeError
- Value of invalid type given.
ValueError
- Value of invalid value given.
icon
andunicode_emoji
are mutually exclusive.
(data, ...)
from_dataCreates a role from the given data
at the given guild
. If the role already exists and is not partial, then returns it. However it is partial, then updates it as well.
Parameter | Type | Optional | Keyword only | Default | Description |
---|---|---|---|---|---|
data |
| Role data received from Discord. | |||
guild_id |
|
| The owner guild's identifier. | ||
strong_cache |
|
| Whether the instance should be put into its strong cache. |
Returns
role : Role
(...)
icon_url_asReturns the role's icon's image's url. If the role has no icon, then returns None
.
This function is a shared method of Role
-s.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
ext |
|
| The extension of the image's url. Can be any of: | |
size |
|
| The preferred minimal size of the image's url. |
Returns
url : None
, str
Raises
ValueError
If ext
, size
was not passed as any of the expected values.
()
is_defaultReturns whether the role is the default role at it's respective guild.
Returns
is_default : bool
(role_id, ...)
precreatePrecreates a role by creating a partial one with the given parameters. When the role is loaded, then the precreated one will be picked up. However if the role is precreated when it already exists, then the existing one is picked up and is updated by the given parameters only if it is partial.
Parameter | Type | Optional | Keyword only | Description |
---|---|---|---|---|
role_id |
| The role's id. | ||
guild_id |
| The role's guild or its identifier. | ||
**keyword_parameters | keyword parameters | Additional predefined attributes for the role. | ||
color |
| The role's color. | ||
flags |
| The role's flags. | ||
icon |
| The role's icon.
| ||
manager |
| The role's manager. | ||
manager_metadata |
| The role's manager's metadata. | ||
manager_type | TIf the role is managed, defines by what it is. | |||
mentionable |
| Whether the role can be mentioned. | ||
name |
| The name of the role. | ||
separated |
| Users show up in separated groups by their highest | ||
permissions |
| The permissions of the users having the role. | ||
position |
| The permissions of the users having the role. | ||
unicode_emoji |
| The role's icon as an unicode emoji.
|
Returns
role : Role
Raises
TypeError
If any parameter's type is bad or if unexpected parameter is passed.
ValueError
If an parameter's type is good, but it's value is unacceptable.
(...)
to_dataConverts the role into a json serializable object.
Parameter | Type | Optional | Keyword only | Default | Description |
---|---|---|---|---|---|
defaults |
|
| Whether default field values should be included. | ||
include_internals |
|
| Whether internal fields should be included. |
Returns
data : dict
of (str
, object
) items
()
_clear_cache_permissionClears the role's guild's permission cache.
(role_id, guild_id)
_create_emptyCreates an empty role with the given identifier.
Parameter | Type | Description |
---|---|---|
role_id |
| The role's identifier. |
guild_id |
| The role's guild's identifier. |
Returns
self : Role
The created role.
()
_deleteRemoves the role's references.
Called when the role is deleted.
(data)
_difference_update_attributesUpdates the role with the given data
and returns it's overwritten attributes as a dict
with a attribute-name
- old-value
relation.
Parameter | Type | Description |
---|---|---|
data |
| Role data received from Discord. |
Returns
old_attributes : dict
of (str
, object
) items
All item in the returned dict is optional.
Returned Data Structure
Keys | Values |
---|---|
color | Color |
flags | RoleFlag |
icon | Icon |
managed | bool |
mentionable | bool |
name | str |
permissions | Permission |
position | int |
separated | bool |
unicode_emoji | None , Emoji |
()
_get_hash_partialReturns the role's hash value. This function is called when the role is partial.
Returns
hash_value : int
(other)
_is_equal_partialReturns whether the role is equal to the given one. This function is called when one or both the roles are partial.
Parameter | Type | Description |
---|---|---|
other |
| The other role to compare self to. |
Returns
is_equal : bool
(data)
_set_attributesSets the role's attributes from the given data.
.id
and .guild_id
fields should be already set,
Parameter | Type | Description |
---|---|---|
data |
| Received role data. |
(data)
_update_attributesUpdates the role with the given data
with overwriting it's old attributes.
Parameter | Type | Description |
---|---|---|
data |
| Role data received from Discord. |
()
__eq__Returns whether the two roles are equal.
(code)
__format__Formats the role in a format string.
Parameter | Type | Description |
---|---|---|
code |
| The option on based the result will be formatted. |
Returns
role : str
Examples
>>>> from hata import Role, now_as_id
>>>> role = Role.precreate(now_as_id(), name = 'admiral-general')
>>>> role
<Role name = 'admiral-general', id = 725333995067277312>
>>>> # no code stands for `role.name`.
>>>> f'{role}'
'admiral-general'
>>>> # 'm' stands for mention.
>>>> f'{role:m}'
'<@&725333995067277312>'
>>>> # 'c' stands for created at.
>>>> f'{role:c}'
'2020.06.24-12:58:20'
()
__ge__Returns whether this role's position is higher or equal to the other's.
()
__getattr__Drops a rich attribute error.
()
__gt__Returns whether this role's position is higher than the other's.
()
__hash__Returns the role's hash value.
()
__le__Returns whether this role's position is less or equal to the other's.
()
__lt__Returns whether this role's position is less than the other's.
()
__ne__Returns whether the two roles are equal.
()
__repr__Returns the role's representation.