Class: Discordrb::Role
- Inherits:
-
Object
- Object
- Discordrb::Role
- Includes:
- IDObject
- Defined in:
- lib/discordrb/data.rb
Overview
A Discord role that contains permissions and applies to certain users
Defined Under Namespace
Classes: RoleWriter
Instance Attribute Summary collapse
-
#colour ⇒ ColourRGB
(also: #color)
The role colour.
-
#hoist ⇒ true, false
Whether or not this role should be displayed separately from other users.
-
#mentionable ⇒ true, false
(also: #mentionable?)
Whether this role can be mentioned using a role mention.
-
#name ⇒ String
This role's name ("new role" if it hasn't been changed).
-
#permissions ⇒ Permissions
readonly
This role's permissions.
-
#position ⇒ Integer
readonly
The position of this role in the hierarchy.
Attributes included from IDObject
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes this role.
-
#inspect ⇒ Object
The inspect method is overwritten to give more useful output.
-
#members ⇒ Array<Member>
(also: #users)
An array of members who have this role.
-
#mention ⇒ String
A string that will mention this role, if it is mentionable.
-
#packed=(packed, update_perms = true) ⇒ Object
Changes this role's permissions to a fixed bitfield.
Methods included from IDObject
#==, #creation_time, synthesise
Instance Attribute Details
#colour ⇒ ColourRGB Also known as: color
Returns the role colour.
789 790 791 |
# File 'lib/discordrb/data.rb', line 789 def colour @colour end |
#hoist ⇒ true, false
Returns whether or not this role should be displayed separately from other users.
782 783 784 |
# File 'lib/discordrb/data.rb', line 782 def hoist @hoist end |
#mentionable ⇒ true, false Also known as: mentionable?
Returns whether this role can be mentioned using a role mention.
785 786 787 |
# File 'lib/discordrb/data.rb', line 785 def mentionable @mentionable end |
#name ⇒ String
Returns this role's name ("new role" if it hasn't been changed).
779 780 781 |
# File 'lib/discordrb/data.rb', line 779 def name @name end |
#permissions ⇒ Permissions (readonly)
Returns this role's permissions.
776 777 778 |
# File 'lib/discordrb/data.rb', line 776 def @permissions end |
#position ⇒ Integer (readonly)
Returns the position of this role in the hierarchy.
793 794 795 |
# File 'lib/discordrb/data.rb', line 793 def position @position end |
Instance Method Details
#delete ⇒ Object
Deletes this role. This cannot be undone without recreating the role!
907 908 909 910 |
# File 'lib/discordrb/data.rb', line 907 def delete API::Server.delete_role(@bot.token, @server.id, @id) @server.delete_role(@id) end |
#inspect ⇒ Object
The inspect method is overwritten to give more useful output
913 914 915 |
# File 'lib/discordrb/data.rb', line 913 def inspect "<Role name=#{@name} permissions=#{@permissions.inspect} hoist=#{@hoist} colour=#{@colour.inspect} server=#{@server.inspect}>" end |
#members ⇒ Array<Member> Also known as: users
This requests a member chunk if it hasn't for the server before, which may be slow initially
Returns an array of members who have this role.
838 839 840 |
# File 'lib/discordrb/data.rb', line 838 def members @server.members.select { |m| m.role? role } end |
#mention ⇒ String
Returns a string that will mention this role, if it is mentionable.
832 833 834 |
# File 'lib/discordrb/data.rb', line 832 def mention "<@&#{@id}>" end |
#packed=(packed, update_perms = true) ⇒ Object
Changes this role's permissions to a fixed bitfield. This allows setting multiple permissions at once with just one API call.
Information on how this bitfield is structured can be found at https://discordapp.com/developers/docs/topics/permissions.
901 902 903 904 |
# File 'lib/discordrb/data.rb', line 901 def packed=(packed, update_perms = true) update_role_data(permissions: packed) @permissions.bits = packed if update_perms end |