class Discorb::Member
Represents a member of a guild.
Attributes
@return [Discorb::Asset] The custom avatar of the member. @return [nil] If the member has no custom avatar.
@return [Boolean] Whether the member is deafened.
@return [Boolean] Whether the member is deafened.
@return [Discorb::Asset] The display avatar of the member.
@return [Time] The time the member joined the guild.
@return [Boolean] Whether the member is muted.
@return [Boolean] Whether the member is muted.
@return [String] The nickname of the member. @return [nil] If the member has no nickname.
@return [Boolean] Whether the member is pending (Not passed member screening).
@return [Boolean] Whether the member is pending (Not passed member screening).
Public Class Methods
@!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
# File lib/discorb/member.rb, line 130 def activities presence&.activities end
# File lib/discorb/member.rb, line 126 def activity presence&.activity end
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 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 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
# File lib/discorb/member.rb, line 102 def guild @client.guilds[@guild_id] end
# File lib/discorb/member.rb, line 118 def hoisted? !@hoisted_role_id.nil? end
# File lib/discorb/member.rb, line 114 def hoisted_role @hoisted_role_id && guild.roles[@hoisted_role_id] end
# File lib/discorb/member.rb, line 138 def inspect "#<#{self.class} #{self} id=#{@id}>" end
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
# File lib/discorb/member.rb, line 94 def mention "<@#{@nick.nil? ? "" : "!"}#{@id}>" end
# File lib/discorb/member.rb, line 90 def name @nick || @username end
# File lib/discorb/member.rb, line 110 def permissions roles.map(&:permissions).sum(Permission.new(0)) end
# File lib/discorb/member.rb, line 122 def presence guild.presences[@id] end
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
# File lib/discorb/member.rb, line 106 def roles @role_ids.map { |r| guild.roles[r] } end
# File lib/discorb/member.rb, line 134 def status presence&.status end
Format the member to `@name` style.
@return [String] The formatted member.
# File lib/discorb/member.rb, line 77 def to_s "@#{name}" end
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
# File lib/discorb/member.rb, line 98 def voice_state guild.voice_states[@id] end
Private Instance Methods
# 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