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.
 - 
  
    
      #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) -> Object 
    
    
      (also: #destroy!)
    
  
  
  
  
  
  
  
  
  
    
Deletes the role.
 - 
  
    
      #edit(name: :unset, position: :unset, color: :unset, hoist: :unset, mentionable: :unset, reason: nil) -> Object 
    
    
      (also: #modify)
    
  
  
  
  
  
  
  
  
  
    
Edits the role.
 - #inspect -> Object
 - #mention -> Object
 - 
  
    
      #move(position, reason: nil) -> Object 
    
    
  
  
  
  
  
  
  
  
  
    
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  | 
  
#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.
      54 55 56 57 58  | 
    
      # File 'lib/discorb/role.rb', line 54 def <=>(other) return false unless other.is_a?(Role) @position <=> other.position end  | 
  
#color? -> Boolean
      73 74 75  | 
    
      # File 'lib/discorb/role.rb', line 73 def color? @color != 0 end  | 
  
#delete!(reason: nil) -> Object Also known as: destroy!
Deletes the role.
      127 128 129 130 131  | 
    
      # File 'lib/discorb/role.rb', line 127 def delete!(reason: nil) Async do @client.http.delete("/guilds/#{@guild_id}/roles/#{@id}", reason: reason).wait end end  | 
  
#edit(name: :unset, position: :unset, color: :unset, hoist: :unset, mentionable: :unset, reason: nil) -> Object Also known as: modify
This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.
This method calls HTTP request.
The arguments of this method are defaultly set to :unset. Specify value to set the value, if not don't specify or specify :unset.
Edits the role.
      108 109 110 111 112 113 114 115 116 117 118  | 
    
      # File 'lib/discorb/role.rb', line 108 def edit(name: :unset, position: :unset, color: :unset, hoist: :unset, mentionable: :unset, reason: nil) Async do payload = {} payload[:name] = name if name != :unset payload[:position] = position if position != :unset payload[:color] = color.to_i if color != :unset payload[:hoist] = hoist if hoist != :unset payload[:mentionable] = mentionable if mentionable != :unset @client.http.patch("/guilds/#{@guild_id}/roles/#{@id}", payload, reason: reason).wait end end  | 
  
#inspect -> Object
      77 78 79  | 
    
      # File 'lib/discorb/role.rb', line 77 def inspect "#<#{self.class} @#{@name} id=#{@id}>" end  | 
  
#mention -> Object
      69 70 71  | 
    
      # File 'lib/discorb/role.rb', line 69 def mention "<@&#{@id}>" end  | 
  
#move(position, reason: nil) -> Object
This is an asynchronous method, it will return a Async::Task object. Use Async::Task#wait to get the result.
This method calls HTTP request.
Moves the role to a new position.
      89 90 91 92 93  | 
    
      # File 'lib/discorb/role.rb', line 89 def move(position, reason: nil) Async do @client.http.patch("/guilds/#{@guild_id}/roles", { id: @id, position: position }, reason: reason).wait end end  | 
  
#tag -> Object Also known as:
      135 136 137  | 
    
      # File 'lib/discorb/role.rb', line 135 def tag Tag.new(@tags) end  | 
  
#to_s -> String
Formats the role as a string.
      65 66 67  | 
    
      # File 'lib/discorb/role.rb', line 65 def to_s "@#{@name}" end  |