Class: Discorb::Role
- Inherits:
-
DiscordModel
- Object
- DiscordModel
- Discorb::Role
- Includes:
- Comparable
- Defined in:
- lib/discorb/role.rb
Overview
Represents a role in the guild.
Defined Under Namespace
Classes: Tag
Instance Attribute Summary collapse
-
#color -> Discorb::Color
readonly
The color of the role.
-
#custom_icon -> Discorb::Asset?
readonly
The icon of the role.
-
#emoji -> Discorb::Emoji?
readonly
The emoji of the role.
-
#guild -> Discorb::Guild
readonly
The guild this role belongs to.
-
#hoist -> Boolean
(also: #hoist?)
readonly
Whether the role is hoisted.
-
#id -> Discorb::Snowflake
readonly
The ID of the role.
-
#managed -> Boolean
(also: #managed?)
readonly
Whether the role is managed.
-
#mentionable -> Boolean
(also: #mentionable?)
readonly
Whether the role is a default role.
-
#name -> String
readonly
The name of the role.
-
#permissions -> Discorb::Permission
readonly
The permissions of the role.
-
#position -> Integer
readonly
The position of the role.
Instance Method Summary collapse
-
#<=>(other) -> Integer
Compares two roles by their position.
- #color? -> Boolean
-
#delete!(reason: nil) -> Async::Task<void>
(also: #destroy!)
Deletes the role.
-
#edit(name: Discorb::Unset, position: Discorb::Unset, color: Discorb::Unset, hoist: Discorb::Unset, mentionable: Discorb::Unset, icon: Discorb::Unset, reason: nil) -> Async::Task<void>
(also: #modify)
Edits the role.
- #icon -> Object
- #inspect -> Object
- #mention -> Object
-
#move(position, reason: nil) -> Async::Task<void>
Moves the role to a new position.
- #tag -> Object (also: #tags)
-
#to_s -> String
Formats the role as a string.
Methods inherited from DiscordModel
Instance Attribute Details
#color -> Discorb::Color (readonly)
Returns The color of the role.
13 14 15 |
# File 'lib/discorb/role.rb', line 13 def color @color end |
#custom_icon -> Discorb::Asset? (readonly)
Returns The icon of the role.
30 31 32 |
# File 'lib/discorb/role.rb', line 30 def custom_icon @custom_icon end |
#emoji -> Discorb::Emoji? (readonly)
Returns The emoji of the role.
32 33 34 |
# File 'lib/discorb/role.rb', line 32 def emoji @emoji end |
#guild -> Discorb::Guild (readonly)
Returns The guild this role belongs to.
19 20 21 |
# File 'lib/discorb/role.rb', line 19 def guild @guild end |
#hoist -> Boolean (readonly) Also known as: hoist?
Returns Whether the role is hoisted.
21 22 23 |
# File 'lib/discorb/role.rb', line 21 def hoist @hoist end |
#id -> Discorb::Snowflake (readonly)
Returns The ID of the role.
9 10 11 |
# File 'lib/discorb/role.rb', line 9 def id @id end |
#managed -> Boolean (readonly) Also known as: managed?
Returns Whether the role is managed.
24 25 26 |
# File 'lib/discorb/role.rb', line 24 def managed @managed end |
#mentionable -> Boolean (readonly) Also known as: mentionable?
Returns Whether the role is a default role.
27 28 29 |
# File 'lib/discorb/role.rb', line 27 def mentionable @mentionable end |
#name -> String (readonly)
Returns The name of the role.
11 12 13 |
# File 'lib/discorb/role.rb', line 11 def name @name end |
#permissions -> Discorb::Permission (readonly)
Returns The permissions of the role.
15 16 17 |
# File 'lib/discorb/role.rb', line 15 def @permissions end |
#position -> Integer (readonly)
Returns The position of the role.
17 18 19 |
# File 'lib/discorb/role.rb', line 17 def position @position end |
Instance Method Details
#<=>(other) -> Integer
Compares two roles by their position.
64 65 66 67 68 |
# File 'lib/discorb/role.rb', line 64 def <=>(other) return false unless other.is_a?(Role) @position <=> other.position end |
#color? -> Boolean
83 84 85 |
# File 'lib/discorb/role.rb', line 83 def color? @color != 0 end |
#delete!(reason: nil) -> Async::Task<void> Also known as: destroy!
Deletes the role.
149 150 151 152 153 |
# File 'lib/discorb/role.rb', line 149 def delete!(reason: nil) Async do @client.http.request(Route.new("/guilds/#{@guild.id}/roles/#{@id}", "//guilds/:guild_id/roles/:role_id", :delete), audit_log_reason: reason).wait end end |
#edit(name: Discorb::Unset, position: Discorb::Unset, color: Discorb::Unset, hoist: Discorb::Unset, mentionable: Discorb::Unset, icon: Discorb::Unset, reason: nil) -> Async::Task<void> Also known as: modify
The arguments of this method are defaultly set to Discorb::Unset
. Specify value to set the value, if not don't specify or specify Discorb::Unset
.
Edits the role.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/discorb/role.rb', line 121 def edit(name: Discorb::Unset, position: Discorb::Unset, color: Discorb::Unset, hoist: Discorb::Unset, mentionable: Discorb::Unset, icon: Discorb::Unset, reason: nil) Async do payload = {} payload[:name] = name if name != Discorb::Unset payload[:position] = position if position != Discorb::Unset payload[:color] = color.to_i if color != Discorb::Unset payload[:hoist] = hoist if hoist != Discorb::Unset payload[:mentionable] = mentionable if mentionable != Discorb::Unset if icon != Discorb::Unset if icon.is_a?(Discorb::Image) payload[:icon] = icon.to_s else payload[:unicode_emoji] = icon.to_s end end @client.http.request(Route.new("/guilds/#{@guild.id}/roles/#{@id}", "//guilds/:guild_id/roles/:role_id", :patch), payload, audit_log_reason: reason).wait end end |
#icon -> Object
53 54 55 |
# File 'lib/discorb/role.rb', line 53 def icon @custom_icon || @emoji end |
#inspect -> Object
87 88 89 |
# File 'lib/discorb/role.rb', line 87 def inspect "#<#{self.class} @#{@name} id=#{@id}>" end |
#mention -> Object
79 80 81 |
# File 'lib/discorb/role.rb', line 79 def mention "<@&#{@id}>" end |
#move(position, reason: nil) -> Async::Task<void>
Moves the role to a new position.
100 101 102 103 104 |
# File 'lib/discorb/role.rb', line 100 def move(position, reason: nil) Async do @client.http.request(Route.new("/guilds/#{@guild.id}/roles", "//guilds/:guild_id/roles", :patch), { id: @id, position: position }, audit_log_reason: reason).wait end end |
#tag -> Object Also known as:
157 158 159 |
# File 'lib/discorb/role.rb', line 157 def tag Tag.new(@tags) end |
#to_s -> String
Formats the role as a string.
75 76 77 |
# File 'lib/discorb/role.rb', line 75 def to_s "@#{@name}" end |