Class: Discorb::Member

Inherits:
User show all
Defined in:
lib/discorb/member.rb

Overview

Represents a member of a guild.

Instance Attribute Summary collapse

Attributes inherited from User

#avatar, #bot, #created_at, #discriminator, #flag, #id, #username, #verified

Instance Method Summary collapse

Methods inherited from User

#bot_owner?

Methods included from Messageable

#delete_message, #edit_message, #fetch_message, #fetch_messages, #fetch_pins, #pin_message, #post, #typing, #unpin_message

Methods inherited from DiscordModel

#==, #eql?

Instance Attribute Details

#activitiesnil, Array<Discorb::Presence::Activity> (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:



# File 'lib/discorb/member.rb', line 30

#activitynil, Discorb::Presence::Activity (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:



# File 'lib/discorb/member.rb', line 30

#custom_avatarDiscorb::Asset? (readonly)

Returns:

  • (Discorb::Asset)

    The custom avatar of the member.

  • (nil)

    If the member has no custom avatar.



17
18
19
# File 'lib/discorb/member.rb', line 17

def custom_avatar
  @custom_avatar
end

#deafBoolean (readonly) Also known as: deaf?

Returns Whether the member is deafened.

Returns:

  • (Boolean)

    Whether the member is deafened.



24
25
26
# File 'lib/discorb/member.rb', line 24

def deaf
  @deaf
end

#display_avatarDiscorb::Asset (readonly)

Returns The display avatar of the member.

Returns:



19
20
21
# File 'lib/discorb/member.rb', line 19

def display_avatar
  @display_avatar
end

#guildnil, Discorb::Guild (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (nil)

    The object wasn't cached.

  • (Discorb::Guild)

    The guild the member is in.



# File 'lib/discorb/member.rb', line 30

#hoisted?Boolean (readonly)

Returns Whether the member has a hoisted role.

Returns:

  • (Boolean)

    Whether the member has a hoisted role.



# File 'lib/discorb/member.rb', line 30

#hoisted_rolenil, Discorb::Role (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (nil)

    The object wasn't cached.

  • (Discorb::Role)

    The hoisted role of the member.

  • (nil)

    If the member has no hoisted role.



# File 'lib/discorb/member.rb', line 30

#joined_atTime (readonly)

Returns The time the member joined the guild.

Returns:

  • (Time)

    The time the member joined the guild.



14
15
16
# File 'lib/discorb/member.rb', line 14

def joined_at
  @joined_at
end

#mentionString (readonly)

Returns The mention of the member.

Returns:

  • (String)

    The mention of the member.



# File 'lib/discorb/member.rb', line 30

#muteBoolean (readonly) Also known as: mute?

Returns Whether the member is muted.

Returns:

  • (Boolean)

    Whether the member is muted.



21
22
23
# File 'lib/discorb/member.rb', line 21

def mute
  @mute
end

#nameString (readonly)

Returns The display name of the member.

Returns:

  • (String)

    The display name of the member.



# File 'lib/discorb/member.rb', line 30

#nickString? (readonly)

Returns:

  • (String)

    The nickname of the member.

  • (nil)

    If the member has no nickname.



12
13
14
# File 'lib/discorb/member.rb', line 12

def nick
  @nick
end

#owner?Boolean (readonly)

Returns Whether the member is the owner of the guild.

Returns:

  • (Boolean)

    Whether the member is the owner of the guild.



# File 'lib/discorb/member.rb', line 30

#pendingBoolean (readonly) Also known as: pending?

Returns Whether the member is pending (Not passed member screening).

Returns:

  • (Boolean)

    Whether the member is pending (Not passed member screening).



27
28
29
# File 'lib/discorb/member.rb', line 27

def pending
  @pending
end

#permissionsDiscorb::Permission (readonly) Also known as: guild_permissions

Returns The permissions of the member.

Returns:



# File 'lib/discorb/member.rb', line 30

#premium_sinceTime (readonly)

Returns The time the member boosted the guild.

Returns:

  • (Time)

    The time the member boosted the guild.



9
10
11
# File 'lib/discorb/member.rb', line 9

def premium_since
  @premium_since
end

#presencenil, Discorb::Presence (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (nil)

    The object wasn't cached.

  • (Discorb::Presence)

    The presence of the member.



# File 'lib/discorb/member.rb', line 30

#rolesnil, Array<Discorb::Role> (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (nil)

    The object wasn't cached.

  • (Array<Discorb::Role>)

    The roles of the member.



# File 'lib/discorb/member.rb', line 30

#statusnil, Symbol (readonly)

Note:

This method returns an object from client cache. it will return nil if the object is not in cache.

Returns:

  • (nil)

    The object wasn't cached.

  • (Symbol)

    The status of the member. It's from the #presence.



# File 'lib/discorb/member.rb', line 30

#voice_stateDiscorb::VoiceState (readonly)

Returns The voice state of the member.

Returns:



# File 'lib/discorb/member.rb', line 30

Instance Method Details

#add_role(role, reason: nil) ⇒ Async::Task<void>

Add a role to the member.

Parameters:

  • role (Discorb::Role)

    The role to add.

  • reason (String) (defaults to: nil)

    The reason for the action.

Returns:

  • (Async::Task<void>)

    The task.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/discorb/member.rb', line 161

def add_role(role, reason: nil)
  Async do
    @client
      .http
      .request(
        Route.new(
          "/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}",
          "//guilds/:guild_id/members/:user_id/roles/:role_id",
          :put
        ),
        nil,
        audit_log_reason: reason
      )
      .wait
  end
end

#ban(delete_message_days: 0, reason: nil) ⇒ Async::Task<Discorb::Guild::Ban>

Ban the member.

Parameters:

  • delete_message_days (Integer) (defaults to: 0)

    The number of days to delete messages.

  • reason (String) (defaults to: nil)

    The reason for the action.

Returns:



297
298
299
300
301
302
303
304
305
# File 'lib/discorb/member.rb', line 297

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

#can_manage?(role) ⇒ Boolean

Checks if the member can manage the given role.

Parameters:

Returns:

  • (Boolean)

    true if the member can manage the role.



314
315
316
317
318
319
# File 'lib/discorb/member.rb', line 314

def can_manage?(role)
  return true if owner?

  top_role = roles.max_by(&:position)
  top_role.position > role.position
end

#edit(nick: Discorb::Unset, role: Discorb::Unset, mute: Discorb::Unset, deaf: Discorb::Unset, channel: Discorb::Unset, communication_disabled_until: Discorb::Unset, timeout_until: Discorb::Unset, reason: nil) ⇒ Async::Task<void> Also known as: modify

Note:

The arguments of this method are defaultly set to Discorb::Unset. Specify value to set the value, if not don't specify or specify Discorb::Unset.

Edit the member.

Parameters:

  • nick (String) (defaults to: Discorb::Unset)

    The nickname of the member.

  • role (Discorb::Role) (defaults to: Discorb::Unset)

    The roles of the member.

  • mute (Boolean) (defaults to: Discorb::Unset)

    Whether the member is muted.

  • deaf (Boolean) (defaults to: Discorb::Unset)

    Whether the member is deafened.

  • channel (Discorb::StageChannel) (defaults to: Discorb::Unset)

    The channel the member is moved to.

  • communication_disabled_until (Time, nil) (defaults to: Discorb::Unset)

    The time the member is timed out. Set to nil to end the timeout.

  • timeout_until (Time, nil) (defaults to: Discorb::Unset)

    Alias of communication_disabled_until.

  • reason (String) (defaults to: nil)

    The reason for the action.

Returns:

  • (Async::Task<void>)

    The task.



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/discorb/member.rb', line 220

def edit(
  nick: Discorb::Unset,
  role: Discorb::Unset,
  mute: Discorb::Unset,
  deaf: Discorb::Unset,
  channel: Discorb::Unset,
  communication_disabled_until: Discorb::Unset,
  timeout_until: Discorb::Unset,
  reason: nil
)
  Async do
    payload = {}
    payload[:nick] = nick if nick != Discorb::Unset
    payload[:roles] = role if role != Discorb::Unset
    payload[:mute] = mute if mute != Discorb::Unset
    payload[:deaf] = deaf if deaf != Discorb::Unset
    communication_disabled_until = timeout_until if timeout_until !=
      Discorb::Unset
    if communication_disabled_until != Discorb::Unset
      payload[
        :communication_disabled_until
      ] = communication_disabled_until&.iso8601
    end
    payload[:channel_id] = channel&.id if channel != Discorb::Unset
    @client
      .http
      .request(
        Route.new(
          "/guilds/#{@guild_id}/members/#{@id}",
          "//guilds/:guild_id/members/:user_id",
          :patch
        ),
        payload,
        audit_log_reason: reason
      )
      .wait
  end
end

#inspectObject



148
149
150
# File 'lib/discorb/member.rb', line 148

def inspect
  "#<#{self.class} #{self} id=#{@id}>"
end

#kick(reason: nil) ⇒ Async::Task<void>

Kick the member.

Parameters:

  • reason (String) (defaults to: nil)

    The reason for the action.

Returns:

  • (Async::Task<void>)

    The task.



284
285
286
# File 'lib/discorb/member.rb', line 284

def kick(reason: nil)
  Async { guild.kick_member(self, reason: reason).wait }
end

#remove_role(role, reason: nil) ⇒ Async::Task<void>

Remove a role to the member.

Parameters:

  • role (Discorb::Role)

    The role to add.

  • reason (String) (defaults to: nil)

    The reason for the action.

Returns:

  • (Async::Task<void>)

    The task.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/discorb/member.rb', line 187

def remove_role(role, reason: nil)
  Async do
    @client
      .http
      .request(
        Route.new(
          "/guilds/#{@guild_id}/members/#{@id}/roles/#{role.is_a?(Role) ? role.id : role}",
          "//guilds/:guild_id/members/:user_id/roles/:role_id",
          :delete
        ),
        {},
        audit_log_reason: reason
      )
      .wait
  end
end

#timeout(time, reason: nil) ⇒ Async::Task<void> Also known as: disable_communication

Timeout the member.

Parameters:

  • time (Time)

    The time until the member is timeout.

  • reason (String) (defaults to: nil)

    The reason for the action.

Returns:

  • (Async::Task<void>)

    The task.



270
271
272
# File 'lib/discorb/member.rb', line 270

def timeout(time, reason: nil)
  edit(communication_disabled_until: time, reason: reason)
end

#to_sString

Format the member to Username#Discriminator style.

Returns:

  • (String)

    The formatted member.



87
88
89
# File 'lib/discorb/member.rb', line 87

def to_s
  "#{username}##{discriminator}"
end