Class: Discordrb::Member

Inherits:
User
  • Object
show all
Includes:
MemberAttributes, PermissionCalculator
Defined in:
lib/discordrb/data.rb

Overview

A member is a user on a server. It differs from regular users in that it has roles, voice statuses and things like that.

Instance Attribute Summary

Attributes included from MemberAttributes

#deaf, #joined_at, #mute, #roles, #server, #voice_channel

Attributes inherited from User

#game, #status

Attributes included from UserAttributes

#avatar_id, #bot_account, #discriminator, #username

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from PermissionCalculator

#defined_permission?, #permission?

Methods inherited from User

#await, #current_bot?, #on, #pm

Methods included from UserAttributes

#avatar_url, #distinct, #mention

Methods included from IDObject

#==, #creation_time

Instance Method Details

#add_role(role) ⇒ Object

Adds one or more roles to this member.

Parameters:

  • role (Role, Array<Role>)

    The role(s) to add.



343
344
345
346
347
348
349
# File 'lib/discordrb/data.rb', line 343

def add_role(role)
  role_ids = role_id_array(role)
  old_role_ids = @roles.map(&:id)
  new_role_ids = (old_role_ids + role_ids).uniq

  API.update_user_roles(@bot.token, @server.id, @user.id, new_role_ids)
end

#inspectObject

Overwriting inspect for debug purposes



384
385
386
# File 'lib/discordrb/data.rb', line 384

def inspect
  "<Member user=#{@user.inspect} server=#{@server.inspect} joined_at=#{@joined_at} roles=#{@roles.inspect} voice_channel=#{@voice_channel.inspect} mute=#{@mute} deaf=#{@deaf} self_mute=#{@self_mute} self_deaf=#{@self_deaf}>"
end

#owner?true, false

Returns whether this member is the server owner.

Returns:

  • (true, false)

    whether this member is the server owner.



337
338
339
# File 'lib/discordrb/data.rb', line 337

def owner?
  @server.owner == self
end

#remove_role(role) ⇒ Object

Removes one or more roles from this member.

Parameters:

  • role (Role, Array<Role>)

    The role(s) to remove.



353
354
355
356
357
358
359
# File 'lib/discordrb/data.rb', line 353

def remove_role(role)
  old_role_ids = @roles.map(&:id)
  role_ids = role_id_array(role)
  new_role_ids = old_role_ids.reject { |i| role_ids.include?(i) }

  API.update_user_roles(@bot.token, @server.id, @user.id, new_role_ids)
end