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, #nick, #roles, #self_deaf, #self_mute, #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.



370
371
372
373
374
375
376
# File 'lib/discordrb/data.rb', line 370

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

#display_nameString



401
402
403
# File 'lib/discordrb/data.rb', line 401

def display_name
  nickname || username
end

#inspectObject

Overwriting inspect for debug purposes



435
436
437
# File 'lib/discordrb/data.rb', line 435

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

#nick=(nick) ⇒ Object Also known as: nickname=

Sets or resets this member's nickname. Requires the Change Nickname permission for the bot itself and Manage Nicknames for other users.



391
392
393
394
395
396
# File 'lib/discordrb/data.rb', line 391

def nick=(nick)
  # Discord uses the empty string to signify 'no nickname' so we convert nil into that
  nick ||= ''

  API.change_nickname(@bot.token, @server.id, @user.id, nick)
end

#owner?true, false



357
358
359
# File 'lib/discordrb/data.rb', line 357

def owner?
  @server.owner == self
end

#remove_role(role) ⇒ Object

Removes one or more roles from this member.



380
381
382
383
384
385
386
# File 'lib/discordrb/data.rb', line 380

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

#role?(role) ⇒ true, false



363
364
365
366
# File 'lib/discordrb/data.rb', line 363

def role?(role)
  role = role.resolve_id
  @roles.any? { |e| e.id == role }
end