Class: RubyCord::Guild::Role
- Inherits:
-
DiscordModel
- Object
- DiscordModel
- RubyCord::Guild::Role
- Includes:
- Comparable
- Defined in:
- lib/rubycord/guild/role.rb
Defined Under Namespace
Classes: Tag
Instance Attribute Summary collapse
-
#color ⇒ RubyCord::Color
readonly
The color of the role.
-
#color? ⇒ Boolean
readonly
Whether the role has a color.
-
#custom_icon ⇒ RubyCord::Asset?
readonly
The icon of the role.
-
#emoji ⇒ RubyCord::Emoji?
readonly
The emoji of the role.
-
#guild ⇒ RubyCord::Guild
readonly
The guild this role belongs to.
-
#hoist ⇒ Boolean
(also: #hoist?)
readonly
Whether the role is hoisted.
-
#icon ⇒ RubyCord::Asset, RubyCord::Emoji
readonly
The icon of the role.
-
#id ⇒ RubyCord::Snowflake
readonly
The ID of the role.
-
#managed ⇒ Boolean
(also: #managed?)
readonly
Whether the role is managed.
-
#mention ⇒ String
readonly
The mention of the role.
-
#mentionable ⇒ Boolean
(also: #mentionable?)
readonly
Whether the role is a default role.
-
#name ⇒ String
readonly
The name of the role.
-
#permissions ⇒ RubyCord::Permission
readonly
The permissions of the role.
-
#position ⇒ Integer
readonly
The position of the role.
-
#tag ⇒ RubyCord::Role::Tag
(also: #tags)
readonly
The tag of the role.
Instance Method Summary collapse
-
#<=>(other) ⇒ Integer
Compares two roles by their position.
-
#delete(reason: nil) ⇒ Async::Task<void>
(also: #destroy)
Deletes the role.
-
#edit(name: RubyCord::Unset, position: RubyCord::Unset, color: RubyCord::Unset, hoist: RubyCord::Unset, mentionable: RubyCord::Unset, icon: RubyCord::Unset, reason: nil) ⇒ Async::Task<void>
(also: #modify)
Edits the role.
- #inspect ⇒ Object
-
#move(position, reason: nil) ⇒ Async::Task<void>
Moves the role to a new position.
-
#to_s ⇒ String
Formats the role as a string.
Methods inherited from DiscordModel
Instance Attribute Details
#color ⇒ RubyCord::Color (readonly)
Returns The color of the role.
16 17 18 |
# File 'lib/rubycord/guild/role.rb', line 16 def color @color end |
#color? ⇒ Boolean (readonly)
Returns Whether the role has a color.
|
# File 'lib/rubycord/guild/role.rb', line 37
|
#custom_icon ⇒ RubyCord::Asset? (readonly)
Returns The icon of the role.
33 34 35 |
# File 'lib/rubycord/guild/role.rb', line 33 def custom_icon @custom_icon end |
#emoji ⇒ RubyCord::Emoji? (readonly)
Returns The emoji of the role.
35 36 37 |
# File 'lib/rubycord/guild/role.rb', line 35 def emoji @emoji end |
#guild ⇒ RubyCord::Guild (readonly)
Returns The guild this role belongs to.
22 23 24 |
# File 'lib/rubycord/guild/role.rb', line 22 def guild @guild end |
#hoist ⇒ Boolean (readonly) Also known as: hoist?
Returns Whether the role is hoisted.
24 25 26 |
# File 'lib/rubycord/guild/role.rb', line 24 def hoist @hoist end |
#icon ⇒ RubyCord::Asset, RubyCord::Emoji (readonly)
Returns The icon of the role.
|
# File 'lib/rubycord/guild/role.rb', line 37
|
#id ⇒ RubyCord::Snowflake (readonly)
Returns The ID of the role.
12 13 14 |
# File 'lib/rubycord/guild/role.rb', line 12 def id @id end |
#managed ⇒ Boolean (readonly) Also known as: managed?
Returns Whether the role is managed.
27 28 29 |
# File 'lib/rubycord/guild/role.rb', line 27 def managed @managed end |
#mention ⇒ String (readonly)
Returns The mention of the role.
|
# File 'lib/rubycord/guild/role.rb', line 37
|
#mentionable ⇒ Boolean (readonly) Also known as: mentionable?
Returns Whether the role is a default role.
30 31 32 |
# File 'lib/rubycord/guild/role.rb', line 30 def mentionable @mentionable end |
#name ⇒ String (readonly)
Returns The name of the role.
14 15 16 |
# File 'lib/rubycord/guild/role.rb', line 14 def name @name end |
#permissions ⇒ RubyCord::Permission (readonly)
Returns The permissions of the role.
18 19 20 |
# File 'lib/rubycord/guild/role.rb', line 18 def end |
#position ⇒ Integer (readonly)
Returns The position of the role.
20 21 22 |
# File 'lib/rubycord/guild/role.rb', line 20 def position @position end |
#tag ⇒ RubyCord::Role::Tag (readonly) Also known as:
Returns The tag of the role.
|
# File 'lib/rubycord/guild/role.rb', line 37
|
Instance Method Details
#<=>(other) ⇒ Integer
Compares two roles by their position.
72 73 74 75 76 |
# File 'lib/rubycord/guild/role.rb', line 72 def <=>(other) return nil unless other.is_a?(Role) @position <=> other.position end |
#delete(reason: nil) ⇒ Async::Task<void> Also known as: destroy
Deletes the role.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/rubycord/guild/role.rb', line 187 def delete(reason: nil) Async do @client .http .request( RubyCord::Internal::Route.new( "/guilds/#{@guild.id}/roles/#{@id}", "//guilds/:guild_id/roles/:role_id", :delete ), {}, audit_log_reason: reason ) .wait end end |
#edit(name: RubyCord::Unset, position: RubyCord::Unset, color: RubyCord::Unset, hoist: RubyCord::Unset, mentionable: RubyCord::Unset, icon: RubyCord::Unset, reason: nil) ⇒ Async::Task<void> Also known as: modify
The arguments of this method are defaultly set to RubyCord::Unset
.
Specify value to set the value, if not don't specify or specify RubyCord::Unset
.
Edits the role.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/rubycord/guild/role.rb', line 140 def edit( name: RubyCord::Unset, position: RubyCord::Unset, color: RubyCord::Unset, hoist: RubyCord::Unset, mentionable: RubyCord::Unset, icon: RubyCord::Unset, reason: nil ) Async do payload = {} payload[:name] = name if name != RubyCord::Unset payload[:position] = position if position != RubyCord::Unset payload[:color] = color.to_i if color != RubyCord::Unset payload[:hoist] = hoist if hoist != RubyCord::Unset payload[:mentionable] = mentionable if mentionable != RubyCord::Unset if icon != RubyCord::Unset if icon.is_a?(RubyCord::Image) payload[:icon] = icon.to_s else payload[:unicode_emoji] = icon.to_s end end @client .http .request( RubyCord::Internal::Route.new( "/guilds/#{@guild.id}/roles/#{@id}", "//guilds/:guild_id/roles/:role_id", :patch ), payload, audit_log_reason: reason ) .wait end end |
#inspect ⇒ Object
95 96 97 |
# File 'lib/rubycord/guild/role.rb', line 95 def inspect "#<#{self.class} @#{@name} id=#{@id}>" end |
#move(position, reason: nil) ⇒ Async::Task<void>
Moves the role to a new position.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/rubycord/guild/role.rb', line 108 def move(position, reason: nil) Async do @client .http .request( RubyCord::Internal::Route.new( "/guilds/#{@guild.id}/roles", "//guilds/:guild_id/roles", :patch ), { id: @id, position: }, audit_log_reason: reason ) .wait end end |
#to_s ⇒ String
Formats the role as a string.
83 84 85 |
# File 'lib/rubycord/guild/role.rb', line 83 def to_s "@#{@name}" end |