Class: Discordrb::Member
- Includes:
- MemberAttributes, PermissionCalculator
- Defined in:
- lib/discordrb/data/member.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.
Constant Summary
Constants included from MemberAttributes
Discordrb::MemberAttributes::MEMBER_FLAGS
Constants included from UserAttributes
Instance Attribute Summary
Attributes included from MemberAttributes
#boosting_since, #communication_disabled_until, #flags, #joined_at, #nick, #pending, #server_avatar_decoration, #server_avatar_id, #server_banner_id
Attributes inherited from User
#activities, #client_status, #status
Attributes included from UserAttributes
#avatar_decoration, #avatar_id, #bot_account, #collectibles, #discriminator, #global_name, #primary_server, #public_flags, #system_account, #username, #webhook_account
Attributes included from IDObject
Instance Method Summary collapse
-
#add_role(role, reason = nil) ⇒ Object
Adds one or more roles to this member.
-
#ban(message_days = 0, message_seconds: nil, reason: nil) ⇒ Object
Bans this member from the server.
-
#boosting? ⇒ true, false
If this user is a Nitro Booster of this server.
-
#colour ⇒ ColourRGB?
(also: #color)
The colour this member has.
-
#colour_role ⇒ Role?
(also: #color_role)
The role this member is basing their colour on.
-
#communication_disabled? ⇒ true, false
(also: #timeout?)
Check if the current user has communication disabled.
-
#communication_disabled_until=(timeout_until) ⇒ Object
(also: #timeout=)
Set a user's timeout duration, or remove it by setting the timeout to
nil
. -
#deaf ⇒ true, false
(also: #deafened?)
Whether this member is deafened server-wide.
-
#display_avatar_decoration ⇒ AvatarDecoration?
The avatar decoration that the user displays (server avatar decoration if they have one, user avatar decoration if they have one, nil otherwise).
-
#display_avatar_url(format = nil) ⇒ String?
The avatar that the user has displayed (server avatar if they have one, user avatar if they have one, nil otherwise).
-
#display_banner_url(format = nil) ⇒ String?
The banner that the user has displayed (server banner if they have one, user banner if they have one, nil otherwise).
-
#display_name ⇒ String
The name the user displays as (nickname if they have one, global_name if they have one, username otherwise).
-
#flags=(flags) ⇒ Object
Set the flags for this member.
-
#highest_role ⇒ Role
The highest role this member has.
-
#hoist_role ⇒ Role?
The role this member is being hoisted with.
-
#inspect ⇒ Object
Overwriting inspect for debug purposes.
-
#kick(reason = nil) ⇒ Object
Kicks this member from the server.
-
#modify_roles(add, remove, reason = nil) ⇒ Object
Adds and removes roles from a member.
-
#mute ⇒ true, false
(also: #muted?)
Whether this member is muted server-wide.
- #nick=(nick) ⇒ Object (also: #nickname=)
-
#owner? ⇒ true, false
Whether this member is the server owner.
-
#remove_role(role, reason = nil) ⇒ Object
Removes one or more roles from this member.
-
#role?(role) ⇒ true, false
Whether this member has the specified role.
-
#roles ⇒ Array<Role>
The roles this member has.
- #roles=(role) ⇒ Object
-
#self_deaf ⇒ true, false
(also: #self_deafened?)
Whether this member has deafened themselves.
-
#self_mute ⇒ true, false
(also: #self_muted?)
Whether this member has muted themselves.
-
#server ⇒ Server
The server this member is on.
-
#server_deafen ⇒ Object
Server deafens this member.
-
#server_mute ⇒ Object
Server mutes this member.
-
#server_undeafen ⇒ Object
Server undeafens this member.
-
#server_unmute ⇒ Object
Server unmutes this member.
-
#set_nick(nick, reason = nil) ⇒ Object
(also: #set_nickname)
Sets or resets this member's nickname.
-
#set_roles(role, reason = nil) ⇒ Object
Bulk sets a member's roles.
-
#unban(reason = nil) ⇒ Object
Unbans this member from the server.
-
#voice_channel ⇒ Channel
The voice channel this member is in.
Methods included from PermissionCalculator
#defined_permission?, #permission?
Methods included from MemberAttributes
#server_avatar_url, #server_banner_url
Methods inherited from User
#await, #await!, #banner_id, #current_bot?, #dnd?, #game, #idle?, #offline?, #on, #online?, #pm, #send_file, #stream_type, #stream_url
Methods included from UserAttributes
#avatar_url, #banner_url, #distinct, #mention
Methods included from IDObject
#==, #creation_time, synthesise
Instance Method Details
#add_role(role, reason = nil) ⇒ Object
Adds one or more roles to this member.
228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/discordrb/data/member.rb', line 228 def add_role(role, reason = nil) role_ids = role_id_array(role) if role_ids.count.one? API::Server.add_member_role(@bot.token, @server_id, @user.id, role_ids[0], reason) else old_role_ids = resolve_role_ids new_role_ids = (old_role_ids + role_ids).uniq API::Server.update_member(@bot.token, @server_id, @user.id, roles: new_role_ids, reason: reason) end end |
#ban(message_days = 0, message_seconds: nil, reason: nil) ⇒ Object
Bans this member from the server.
309 310 311 |
# File 'lib/discordrb/data/member.rb', line 309 def ban( = 0, message_seconds: nil, reason: nil) server.ban(@user, , message_seconds: , reason: reason) end |
#boosting? ⇒ true, false
Returns if this user is a Nitro Booster of this server.
161 162 163 |
# File 'lib/discordrb/data/member.rb', line 161 def boosting? !@boosting_since.nil? end |
#colour ⇒ ColourRGB? Also known as: color
Returns the colour this member has.
278 279 280 281 282 |
# File 'lib/discordrb/data/member.rb', line 278 def colour return nil unless colour_role colour_role.color end |
#colour_role ⇒ Role? Also known as: color_role
Returns the role this member is basing their colour on.
269 270 271 272 273 274 |
# File 'lib/discordrb/data/member.rb', line 269 def colour_role coloured_roles = roles.select { |v| v.colour.combined.nonzero? } return nil if coloured_roles.empty? coloured_roles.max_by(&:position) end |
#communication_disabled? ⇒ true, false Also known as: timeout?
Check if the current user has communication disabled.
184 185 186 |
# File 'lib/discordrb/data/member.rb', line 184 def communication_disabled? !@communication_disabled_until.nil? && @communication_disabled_until > Time.now end |
#communication_disabled_until=(timeout_until) ⇒ Object Also known as: timeout=
Set a user's timeout duration, or remove it by setting the timeout to nil
.
192 193 194 195 196 |
# File 'lib/discordrb/data/member.rb', line 192 def communication_disabled_until=(timeout_until) raise ArgumentError, 'A time out cannot exceed 28 days' if timeout_until && timeout_until > (Time.now + 2_419_200) API::Server.update_member(@bot.token, @server_id, @user.id, communication_disabled_until: timeout_until&.iso8601) end |
#deaf ⇒ true, false Also known as: deafened?
Returns whether this member is deafened server-wide.
87 88 89 |
# File 'lib/discordrb/data/member.rb', line 87 def deaf voice_state_attribute(:deaf) end |
#display_avatar_decoration ⇒ AvatarDecoration?
Returns the avatar decoration that the user displays (server avatar decoration if they have one, user avatar decoration if they have one, nil otherwise).
364 365 366 |
# File 'lib/discordrb/data/member.rb', line 364 def display_avatar_decoration server_avatar_decoration || avatar_decoration end |
#display_avatar_url(format = nil) ⇒ String?
Returns the avatar that the user has displayed (server avatar if they have one, user avatar if they have one, nil otherwise).
353 354 355 |
# File 'lib/discordrb/data/member.rb', line 353 def display_avatar_url(format = nil) server_avatar_url(format) || avatar_url(format) end |
#display_banner_url(format = nil) ⇒ String?
Returns the banner that the user has displayed (server banner if they have one, user banner if they have one, nil otherwise).
359 360 361 |
# File 'lib/discordrb/data/member.rb', line 359 def (format = nil) (format) || (format) end |
#display_name ⇒ String
Returns the name the user displays as (nickname if they have one, global_name if they have one, username otherwise).
347 348 349 |
# File 'lib/discordrb/data/member.rb', line 347 def display_name nickname || global_name || username end |
#flags=(flags) ⇒ Object
Set the flags for this member.
370 371 372 |
# File 'lib/discordrb/data/member.rb', line 370 def flags=(flags) API::Server.update_member(@bot.token, @server_id, @user.id, flags: flags) end |
#highest_role ⇒ Role
Returns the highest role this member has.
256 257 258 |
# File 'lib/discordrb/data/member.rb', line 256 def highest_role roles.max_by(&:position) end |
#hoist_role ⇒ Role?
Returns the role this member is being hoisted with.
261 262 263 264 265 266 |
# File 'lib/discordrb/data/member.rb', line 261 def hoist_role hoisted_roles = roles.select(&:hoist) return nil if hoisted_roles.empty? hoisted_roles.max_by(&:position) end |
#inspect ⇒ Object
Overwriting inspect for debug purposes
445 446 447 |
# File 'lib/discordrb/data/member.rb', line 445 def inspect "<Member user=#{@user.inspect} server=#{@server&.inspect || @server_id} joined_at=#{@joined_at} roles=#{@roles&.inspect || @role_ids} voice_channel=#{@voice_channel.inspect} mute=#{@mute} deaf=#{@deaf} self_mute=#{@self_mute} self_deaf=#{@self_deaf}>" end |
#kick(reason = nil) ⇒ Object
Kicks this member from the server.
321 322 323 |
# File 'lib/discordrb/data/member.rb', line 321 def kick(reason = nil) server.kick(@user, reason) end |
#modify_roles(add, remove, reason = nil) ⇒ Object
Adds and removes roles from a member.
216 217 218 219 220 221 222 223 |
# File 'lib/discordrb/data/member.rb', line 216 def modify_roles(add, remove, reason = nil) add_role_ids = role_id_array(add) remove_role_ids = role_id_array(remove) old_role_ids = resolve_role_ids new_role_ids = (old_role_ids - remove_role_ids + add_role_ids).uniq API::Server.update_member(@bot.token, @server_id, @user.id, roles: new_role_ids, reason: reason) end |
#mute ⇒ true, false Also known as: muted?
Returns whether this member is muted server-wide.
82 83 84 |
# File 'lib/discordrb/data/member.rb', line 82 def mute voice_state_attribute(:mute) end |
#nick=(nick) ⇒ Object Also known as: nickname=
326 327 328 |
# File 'lib/discordrb/data/member.rb', line 326 def nick=(nick) set_nick(nick) end |
#owner? ⇒ true, false
Returns whether this member is the server owner.
166 167 168 |
# File 'lib/discordrb/data/member.rb', line 166 def owner? server.owner == self end |
#remove_role(role, reason = nil) ⇒ Object
Removes one or more roles from this member.
243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/discordrb/data/member.rb', line 243 def remove_role(role, reason = nil) role_ids = role_id_array(role) if role_ids.count.one? API::Server.remove_member_role(@bot.token, @server_id, @user.id, role_ids[0], reason) else old_role_ids = resolve_role_ids new_role_ids = old_role_ids.reject { |i| role_ids.include?(i) } API::Server.update_member(@bot.token, @server_id, @user.id, roles: new_role_ids, reason: reason) end end |
#role?(role) ⇒ true, false
Returns whether this member has the specified role.
172 173 174 175 |
# File 'lib/discordrb/data/member.rb', line 172 def role?(role) role = role.resolve_id roles.any?(role) end |
#roles ⇒ Array<Role>
Returns the roles this member has.
153 154 155 156 157 158 |
# File 'lib/discordrb/data/member.rb', line 153 def roles return @roles if @roles update_roles(@role_ids) @roles end |
#roles=(role) ⇒ Object
178 179 180 |
# File 'lib/discordrb/data/member.rb', line 178 def roles=(role) set_roles(role) end |
#self_deaf ⇒ true, false Also known as: self_deafened?
Returns whether this member has deafened themselves.
97 98 99 |
# File 'lib/discordrb/data/member.rb', line 97 def self_deaf voice_state_attribute(:self_deaf) end |
#self_mute ⇒ true, false Also known as: self_muted?
Returns whether this member has muted themselves.
92 93 94 |
# File 'lib/discordrb/data/member.rb', line 92 def self_mute voice_state_attribute(:self_mute) end |
#server ⇒ Server
Returns the server this member is on.
141 142 143 144 145 146 147 148 |
# File 'lib/discordrb/data/member.rb', line 141 def server return @server if @server @server = @bot.server(@server_id) raise Discordrb::Errors::NoPermission, 'The bot does not have access to this server' unless @server @server end |
#server_deafen ⇒ Object
Server deafens this member.
286 287 288 |
# File 'lib/discordrb/data/member.rb', line 286 def server_deafen API::Server.update_member(@bot.token, @server_id, @user.id, deaf: true) end |
#server_mute ⇒ Object
Server mutes this member.
296 297 298 |
# File 'lib/discordrb/data/member.rb', line 296 def server_mute API::Server.update_member(@bot.token, @server_id, @user.id, mute: true) end |
#server_undeafen ⇒ Object
Server undeafens this member.
291 292 293 |
# File 'lib/discordrb/data/member.rb', line 291 def server_undeafen API::Server.update_member(@bot.token, @server_id, @user.id, deaf: false) end |
#server_unmute ⇒ Object
Server unmutes this member.
301 302 303 |
# File 'lib/discordrb/data/member.rb', line 301 def server_unmute API::Server.update_member(@bot.token, @server_id, @user.id, mute: false) end |
#set_nick(nick, reason = nil) ⇒ Object Also known as: set_nickname
Sets or resets this member's nickname. Requires the Change Nickname permission for the bot itself and Manage Nicknames for other users.
336 337 338 339 340 341 342 |
# File 'lib/discordrb/data/member.rb', line 336 def set_nick(nick, reason = nil) if @user.current_bot? API::Server.update_current_member(@bot.token, @server_id, nick, reason) else API::Server.update_member(@bot.token, @server_id, @user.id, nick: nick, reason: reason) end end |
#set_roles(role, reason = nil) ⇒ Object
Bulk sets a member's roles.
203 204 205 206 |
# File 'lib/discordrb/data/member.rb', line 203 def set_roles(role, reason = nil) role_ids = role_id_array(role) API::Server.update_member(@bot.token, @server_id, @user.id, roles: role_ids, reason: reason) end |
#unban(reason = nil) ⇒ Object
Unbans this member from the server.
315 316 317 |
# File 'lib/discordrb/data/member.rb', line 315 def unban(reason = nil) server.unban(@user, reason) end |
#voice_channel ⇒ Channel
Returns the voice channel this member is in.
102 103 104 |
# File 'lib/discordrb/data/member.rb', line 102 def voice_channel voice_state_attribute(:voice_channel) end |