Method: Discordrb::Member#set_nick

Defined in:
lib/discordrb/data/member.rb

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

Parameters:

  • nick (String, nil)

    The string to set the nickname to, or nil if it should be reset.

  • reason (String) (defaults to: nil)

    The reason the user's nickname is being changed.



279
280
281
282
283
284
285
286
287
288
# File 'lib/discordrb/data/member.rb', line 279

def set_nick(nick, reason = nil)
  # Discord uses the empty string to signify 'no nickname' so we convert nil into that
  nick ||= ''

  if @user.current_bot?
    API::User.change_own_nickname(@bot.token, @server_id, nick, reason)
  else
    API::Server.update_member(@bot.token, @server_id, @user.id, nick: nick, reason: nil)
  end
end