Class: RubyCord::Guild::Member

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

Instance Attribute Summary collapse

Attributes inherited from User

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

Instance Method Summary collapse

Methods inherited from User

#bot_owner?

Methods included from Internal::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<RubyCord::User::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/rubycord/guild/member.rb', line 32

#activitynil, RubyCord::User::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/rubycord/guild/member.rb', line 32

#custom_avatarRubyCord::Asset? (readonly)

Returns:

  • (RubyCord::Asset)

    The custom avatar of the member.

  • (nil)

    If the member has no custom avatar.



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

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.



26
27
28
# File 'lib/rubycord/guild/member.rb', line 26

def deaf
  @deaf
end

#display_avatarRubyCord::Asset (readonly)

Returns The display avatar of the member.

Returns:



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

def display_avatar
  @display_avatar
end

#guildnil, RubyCord::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.

  • (RubyCord::Guild)

    The guild the member is in.



# File 'lib/rubycord/guild/member.rb', line 32

#hoisted?Boolean (readonly)

Returns Whether the member has a hoisted role.

Returns:

  • (Boolean)

    Whether the member has a hoisted role.



# File 'lib/rubycord/guild/member.rb', line 32

#hoisted_rolenil, RubyCord::Guild::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.

  • (RubyCord::Guild::Role)

    The hoisted role of the member.

  • (nil)

    If the member has no hoisted role.



# File 'lib/rubycord/guild/member.rb', line 32

#joined_atTime (readonly)

Returns The time the member joined the guild.

Returns:

  • (Time)

    The time the member joined the guild.



16
17
18
# File 'lib/rubycord/guild/member.rb', line 16

def joined_at
  @joined_at
end

#mentionString (readonly)

Returns The mention of the member.

Returns:

  • (String)

    The mention of the member.



# File 'lib/rubycord/guild/member.rb', line 32

#muteBoolean (readonly) Also known as: mute?

Returns Whether the member is muted.

Returns:

  • (Boolean)

    Whether the member is muted.



23
24
25
# File 'lib/rubycord/guild/member.rb', line 23

def mute
  @mute
end

#nameString (readonly)

Returns The display name of the member.

Returns:

  • (String)

    The display name of the member.



# File 'lib/rubycord/guild/member.rb', line 32

#nickString? (readonly)

Returns:

  • (String)

    The nickname of the member.

  • (nil)

    If the member has no nickname.



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

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/rubycord/guild/member.rb', line 32

#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).



29
30
31
# File 'lib/rubycord/guild/member.rb', line 29

def pending
  @pending
end

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

Returns The permissions of the member.

Returns:



# File 'lib/rubycord/guild/member.rb', line 32

#premium_sinceTime (readonly)

Returns The time the member boosted the guild.

Returns:

  • (Time)

    The time the member boosted the guild.



11
12
13
# File 'lib/rubycord/guild/member.rb', line 11

def premium_since
  @premium_since
end

#presencenil, RubyCord::User::Presence (readonly)

Note:

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

Returns:



# File 'lib/rubycord/guild/member.rb', line 32

#rolesnil, Array<RubyCord::Guild::Role> (readonly)

Note:

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

Returns:



# File 'lib/rubycord/guild/member.rb', line 32

#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/rubycord/guild/member.rb', line 32

#voice_stateRubyCord::Guild::VoiceChannel::VoiceState (readonly)

Returns The voice state of the member.

Returns:



# File 'lib/rubycord/guild/member.rb', line 32

Instance Method Details

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

Add a role to the member.

Parameters:

  • role (RubyCord::Guild::Role)

    The role to add.

  • reason (String) (defaults to: nil)

    The reason for the action.

Returns:

  • (Async::Task<void>)

    The task.



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/rubycord/guild/member.rb', line 168

def add_role(role, reason: nil)
  Async do
    @client
      .http
      .request(
        RubyCord::Internal::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<RubyCord::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:



304
305
306
307
308
309
310
311
312
# File 'lib/rubycord/guild/member.rb', line 304

def ban(delete_message_days: 0, reason: nil)
  Async do
    guild.ban_member(
      self,
      delete_message_days:,
      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.



321
322
323
324
325
326
# File 'lib/rubycord/guild/member.rb', line 321

def can_manage?(role)
  return true if owner?

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

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

Note:

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

Edit the member.

Parameters:

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

    The nickname of the member.

  • role (RubyCord::Guild::Role) (defaults to: RubyCord::Unset)

    The roles of the member.

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

    Whether the member is muted.

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

    Whether the member is deafened.

  • channel (RubyCord::Guild::StageChannel) (defaults to: RubyCord::Unset)

    The channel the member is moved to.

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

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

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

    Alias of communication_disabled_until.

  • reason (String) (defaults to: nil)

    The reason for the action.

Returns:

  • (Async::Task<void>)

    The task.



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
258
259
260
261
262
263
264
# File 'lib/rubycord/guild/member.rb', line 227

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

#inspectString

Returns Object class and attributes.

Returns:

  • (String)

    Object class and attributes.



155
156
157
# File 'lib/rubycord/guild/member.rb', line 155

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.



291
292
293
# File 'lib/rubycord/guild/member.rb', line 291

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

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

Remove a role to the member.

Parameters:

  • role (RubyCord::Guild::Role)

    The role to add.

  • reason (String) (defaults to: nil)

    The reason for the action.

Returns:

  • (Async::Task<void>)

    The task.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/rubycord/guild/member.rb', line 194

def remove_role(role, reason: nil)
  Async do
    @client
      .http
      .request(
        RubyCord::Internal::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.



277
278
279
# File 'lib/rubycord/guild/member.rb', line 277

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

#to_sString

Format the user as Display name (@Username) or Display name#Discriminator style.

Returns:

  • (String)

    The formatted member.



89
90
91
92
93
94
95
# File 'lib/rubycord/guild/member.rb', line 89

def to_s
  if @discriminator == "0"
    "#{name} (@#{@username})"
  else
    "#{username}##{discriminator}"
  end
end