Class: Discordrb::Role

Inherits:
Object
  • Object
show all
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

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from IDObject

#==, #creation_time, synthesise

Instance Attribute Details

#colourColourRGB Also known as: color

Returns the role colour.

Returns:


894
895
896
# File 'lib/discordrb/data.rb', line 894

def colour
  @colour
end

#hoisttrue, false

Returns whether or not this role should be displayed separately from other users.

Returns:

  • (true, false)

    whether or not this role should be displayed separately from other users


883
884
885
# File 'lib/discordrb/data.rb', line 883

def hoist
  @hoist
end

#managedtrue, false (readonly) Also known as: managed?

Returns whether or not this role is managed by a integration or bot.

Returns:

  • (true, false)

    whether or not this role is managed by a integration or bot


886
887
888
# File 'lib/discordrb/data.rb', line 886

def managed
  @managed
end

#mentionabletrue, false Also known as: mentionable?

Returns whether this role can be mentioned using a role mention.

Returns:

  • (true, false)

    whether this role can be mentioned using a role mention


890
891
892
# File 'lib/discordrb/data.rb', line 890

def mentionable
  @mentionable
end

#nameString

Returns this role's name ("new role" if it hasn't been changed).

Returns:

  • (String)

    this role's name ("new role" if it hasn't been changed)


880
881
882
# File 'lib/discordrb/data.rb', line 880

def name
  @name
end

#permissionsPermissions (readonly)

Returns this role's permissions.

Returns:


877
878
879
# File 'lib/discordrb/data.rb', line 877

def permissions
  @permissions
end

#positionInteger (readonly)

Returns the position of this role in the hierarchy.

Returns:

  • (Integer)

    the position of this role in the hierarchy


898
899
900
# File 'lib/discordrb/data.rb', line 898

def position
  @position
end

Instance Method Details

#delete(reason = nil) ⇒ Object

Deletes this role. This cannot be undone without recreating the role!

Parameters:

  • reason (String) (defaults to: nil)

    the reason for this role's deletion


1015
1016
1017
1018
# File 'lib/discordrb/data.rb', line 1015

def delete(reason = nil)
  API::Server.delete_role(@bot.token, @server.id, @id, reason)
  @server.delete_role(@id)
end

#inspectObject

The inspect method is overwritten to give more useful output


1021
1022
1023
# File 'lib/discordrb/data.rb', line 1021

def inspect
  "<Role name=#{@name} permissions=#{@permissions.inspect} hoist=#{@hoist} colour=#{@colour.inspect} server=#{@server.inspect}>"
end

#membersArray<Member> Also known as: users

Note:

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.

Returns:

  • (Array<Member>)

    an array of members who have this role.


944
945
946
# File 'lib/discordrb/data.rb', line 944

def members
  @server.members.select { |m| m.role? self }
end

#mentionString

Returns a string that will mention this role, if it is mentionable.

Returns:

  • (String)

    a string that will mention this role, if it is mentionable.


938
939
940
# File 'lib/discordrb/data.rb', line 938

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.

Examples:

Remove all permissions from a role

role.packed = 0

Parameters:

  • packed (Integer)

    A bitfield with the desired permissions value.

  • update_perms (true, false) (defaults to: true)

    Whether the internal data should also be updated. This should always be true when calling externally.


1008
1009
1010
1011
# File 'lib/discordrb/data.rb', line 1008

def packed=(packed, update_perms = true)
  update_role_data(permissions: packed)
  @permissions.bits = packed if update_perms
end