module Discordrb::UserAttributes

Mixin for the attributes users should have

Constants

FLAGS

rubocop:disable Naming/VariableNumber

Attributes

avatar_id[RW]

@return [String] the ID of this user’s current avatar, can be used to generate an avatar URL. @see avatar_url

bot_account[R]

@return [true, false] whether this user is a Discord bot account

bot_account?[R]

@return [true, false] whether this user is a Discord bot account

discord_tag[R]

@return [String] this user’s discriminator which is used internally to identify users with identical usernames.

discrim[R]

@return [String] this user’s discriminator which is used internally to identify users with identical usernames.

discriminator[R]

@return [String] this user’s discriminator which is used internally to identify users with identical usernames.

global_name[R]

@return [String, nil] this user’s global name

name[R]

@return [String] this user’s username

public_flags[R]

@return [Integer] the public flags on a user’s account

tag[R]

@return [String] this user’s discriminator which is used internally to identify users with identical usernames.

username[R]

@return [String] this user’s username

webhook?[R]

@return [true, false] whether this is fake user for a webhook message

webhook_account[R]

@return [true, false] whether this is fake user for a webhook message

webhook_account?[R]

@return [true, false] whether this is fake user for a webhook message

Public Instance Methods

avatar_url(format = nil) click to toggle source

Utility function to get a user’s avatar URL. @param format [String, nil] If ‘nil`, the URL will default to `webp` for static avatars, and will detect if the user has a `gif` avatar. You can otherwise specify one of `webp`, `jpg`, `png`, or `gif` to override this. Will always be PNG for default avatars. @return [String] the URL to the avatar image. TODO: Maybe change this method again after discriminator removal ?

# File lib/discordrb/data/user.rb, line 79
def avatar_url(format = nil)
  unless @avatar_id
    return API::User.default_avatar(@discriminator, legacy: true) if @discriminator && @discriminator != '0'

    return API::User.default_avatar(@id)
  end

  API::User.avatar_url(@id, @avatar_id, format)
end
display_name() click to toggle source

Utility function to get Discord’s display name of a user not in server @return [String] the name the user displays as (global_name if they have one, username otherwise)

# File lib/discordrb/data/user.rb, line 54
def display_name
  global_name || username
end
distinct() click to toggle source

Utility function to get Discord’s distinct representation of a user, i.e. username + discriminator @return [String] distinct representation of user TODO: Maybe change this method again after discriminator removal ?

# File lib/discordrb/data/user.rb, line 67
def distinct
  if @discriminator && @discriminator != '0'
    "#{@username}##{@discriminator}"
  else
    @username.to_s
  end
end
mention() click to toggle source

Utility function to mention users in messages @return [String] the mention code in the form of <@id>

# File lib/discordrb/data/user.rb, line 60
def mention
  "<@#{@id}>"
end