class Discorb::Member

Represents a member of a guild.

Attributes

custom_avatar[R]

@return [Discorb::Asset] The custom avatar of the member. @return [nil] If the member has no custom avatar.

deaf[R]

@return [Boolean] Whether the member is deafened.

deaf?[R]

@return [Boolean] Whether the member is deafened.

display_avatar[R]

@return [Discorb::Asset] The display avatar of the member.

joined_at[R]

@return [Time] The time the member joined the guild.

mute[R]

@return [Boolean] Whether the member is muted.

mute?[R]

@return [Boolean] Whether the member is muted.

nick[R]

@return [String] The nickname of the member. @return [nil] If the member has no nickname.

pending[R]

@return [Boolean] Whether the member is pending (Not passed member screening).

pending?[R]

@return [Boolean] Whether the member is pending (Not passed member screening).

premium_since[R]

@return [Time] The time the member boosted the guild.

Public Class Methods

new(client, guild_id, user_data, member_data) click to toggle source

@!visibility private

# File lib/discorb/member.rb, line 64
def initialize(client, guild_id, user_data, member_data)
  @guild_id = guild_id
  @client = client
  @_member_data = {}
  @data = {}
  _set_data(user_data, member_data)
end

Public Instance Methods

activities() click to toggle source
# File lib/discorb/member.rb, line 130
def activities
  presence&.activities
end
activity() click to toggle source
# File lib/discorb/member.rb, line 126
def activity
  presence&.activity
end
add_role(role, reason: nil) click to toggle source

Add a role to the member. @macro http @macro async

@param [Discorb::Role] role The role to add. @param [String] reason The reason for the action.

# File lib/discorb/member.rb, line 150
def add_role(role, reason: nil)
  Async do
    @client.http.put("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", nil, audit_log_reason: reason).wait
  end
end
ban(delete_message_days: 0, reason: nil) click to toggle source

Ban the member.

@param [Integer] delete_message_days The number of days to delete messages. @param [String] reason The reason for the action.

@return [Discorb::Guild::Ban] The ban.

# File lib/discorb/member.rb, line 216
def ban(delete_message_days: 0, reason: nil)
  Async do
    guild.ban_member(self, delete_message_days: delete_message_days, reason: reason).wait
  end
end
edit(nick: :unset, role: :unset, mute: :unset, deaf: :unset, channel: :unset, reason: nil) click to toggle source

Edit the member. @macro http @macro async @macro edit

@param [String] nick The nickname of the member. @param [Discorb::Role] role The roles of the member. @param [Boolean] mute Whether the member is muted. @param [Boolean] deaf Whether the member is deafened. @param [Discorb::StageChannel] channel The channel the member is moved to. @param [String] reason The reason for the action.

# File lib/discorb/member.rb, line 183
def edit(nick: :unset, role: :unset, mute: :unset, deaf: :unset, channel: :unset, reason: nil)
  Async do
    payload = {}
    payload[:nick] = nick if nick != :unset
    payload[:roles] = role if role != :unset
    payload[:mute] = mute if mute != :unset
    payload[:deaf] = deaf if deaf != :unset
    payload[:channel_id] = channel&.id if channel != :unset
    @client.http.patch("/guilds/#{@guild_id}/members/#{@id}", payload, audit_log_reason: reason).wait
  end
end
Also aliased as: modify
guild() click to toggle source
# File lib/discorb/member.rb, line 102
def guild
  @client.guilds[@guild_id]
end
hoisted?() click to toggle source
# File lib/discorb/member.rb, line 118
def hoisted?
  !@hoisted_role_id.nil?
end
hoisted_role() click to toggle source
# File lib/discorb/member.rb, line 114
def hoisted_role
  @hoisted_role_id && guild.roles[@hoisted_role_id]
end
inspect() click to toggle source
# File lib/discorb/member.rb, line 138
def inspect
  "#<#{self.class} #{self} id=#{@id}>"
end
kick(reason: nil) click to toggle source

Kick the member.

@param [String] reason The reason for the action.

# File lib/discorb/member.rb, line 202
def kick(reason: nil)
  Async do
    guild.kick_member(self, reason: reason).wait
  end
end
mention() click to toggle source
# File lib/discorb/member.rb, line 94
def mention
  "<@#{@nick.nil? ? "" : "!"}#{@id}>"
end
modify(nick: :unset, role: :unset, mute: :unset, deaf: :unset, channel: :unset, reason: nil)
Alias for: edit
name() click to toggle source
# File lib/discorb/member.rb, line 90
def name
  @nick || @username
end
permissions() click to toggle source
# File lib/discorb/member.rb, line 110
def permissions
  roles.map(&:permissions).sum(Permission.new(0))
end
presence() click to toggle source
# File lib/discorb/member.rb, line 122
def presence
  guild.presences[@id]
end
remove_role(role, reason: nil) click to toggle source

Remove a role to the member. @macro http @macro async

@param [Discorb::Role] role The role to add. @param [String] reason The reason for the action.

# File lib/discorb/member.rb, line 164
def remove_role(role, reason: nil)
  Async do
    @client.http.delete("/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}", audit_log_reason: reason).wait
  end
end
roles() click to toggle source
# File lib/discorb/member.rb, line 106
def roles
  @role_ids.map { |r| guild.roles[r] }
end
status() click to toggle source
# File lib/discorb/member.rb, line 134
def status
  presence&.status
end
to_s() click to toggle source

Format the member to `@name` style.

@return [String] The formatted member.

# File lib/discorb/member.rb, line 77
def to_s
  "@#{name}"
end
to_s_user() click to toggle source

Format the member to `Username#Discriminator` style.

@return [String] The formatted member.

# File lib/discorb/member.rb, line 86
def to_s_user
  "#{username}##{discriminator}"
end
voice_state() click to toggle source
# File lib/discorb/member.rb, line 98
def voice_state
  guild.voice_states[@id]
end

Private Instance Methods

_set_data(user_data, member_data) click to toggle source
Calls superclass method
# File lib/discorb/member.rb, line 224
def _set_data(user_data, member_data)
  user_data ||= member_data[:user]
  @role_ids = member_data[:roles]
  @premium_since = member_data[:premium_since] && Time.iso8601(member_data[:premium_since])
  @pending = member_data[:pending]
  @nick = member_data[:nick]
  @mute = member_data[:mute]
  @joined_at = member_data[:joined_at] && Time.iso8601(member_data[:joined_at])
  @hoisted_role_id = member_data[:hoisted_role]
  @deaf = member_data[:deaf]
  @custom_avatar = member_data[:avatar] && Asset.new(member_data[:avatar])
  super(user_data)
  @display_avatar = @avatar || @custom_avatar
  @client.guilds[@guild_id].members[@id] = self unless @guild_id.nil?
  @_member_data.update(member_data)
end