class Discorb::User

Represents a user of discord.

Attributes

avatar[R]

@return [Discorb::Asset] The user's avatar.

bot[R]

@return [Boolean] Whether the user is a bot.

bot?[R]

@return [Boolean] Whether the user is a bot.

created_at[R]

@return [Time] The time the user was created.

discriminator[R]

@return [String] The user's discriminator.

flag[R]

@return [Discorb::User::Flag] The user's flags.

id[R]

@return [Discorb::Snowflake] The user's ID.

name[R]

@return [String] The user's username.

username[R]

@return [String] The user's username.

verified[R]

@return [Boolean] Whether the user is verified.

Public Class Methods

new(client, data) click to toggle source

@!visibility private

# File lib/discorb/user.rb, line 30
def initialize(client, data)
  @client = client
  @data = {}
  @dm_channel_id = nil
  _set_data(data)
end

Public Instance Methods

app_owner?(strict: false)
Alias for: bot_owner?
bot_owner?(strict: false) click to toggle source

Whether the user is a owner of the client. @macro async @macro http

@param [Boolean] strict Whether don't allow if the user is a member of the team.

@return [Boolean] Whether the user is a owner of the client.

# File lib/discorb/user.rb, line 61
def bot_owner?(strict: false)
  Async do
    app = @client.fetch_application.wait
    if app.team.nil?
      app.owner == self
    elsif strict
      app.team.owner == self
    else
      app.team.members.any? { |m| m.user == self }
    end
  end
end
Also aliased as: app_owner?
channel_id() click to toggle source

@!visibility private

# File lib/discorb/user.rb, line 77
def channel_id
  Async do
    next @dm_channel_id if @dm_channel_id

    _resp, dm_channel = @client.http.post("/users/@me/channels", { recipient_id: @id }).wait
    @dm_channel_id = dm_channel[:id]
    @dm_channel_id
  end
end
inspect() click to toggle source
# File lib/discorb/user.rb, line 48
def inspect
  "#<#{self.class} #{self}>"
end
to_s() click to toggle source

Format the user as `Username#Discriminator` style.

@return [String] The formatted username.

# File lib/discorb/user.rb, line 42
def to_s
  "#{@username}##{@discriminator}"
end
Also aliased as: to_s_user
to_s_user()
Alias for: to_s

Private Instance Methods

_set_data(data) click to toggle source
# File lib/discorb/user.rb, line 124
def _set_data(data)
  @username = data[:username]
  @verified = data[:verified]
  @id = Snowflake.new(data[:id])
  @flag = User::Flag.new(data[:public_flags] | (data[:flags] || 0))
  @discriminator = data[:discriminator]
  @avatar = data[:avatar] ? Asset.new(self, data[:avatar]) : DefaultAvatar.new(data[:discriminator])
  @bot = data[:bot]
  @raw_data = data
  @client.users[@id] = self if !data[:no_cache] && data.is_a?(User)
  @created_at = @id.timestamp
  @data.update(data)
end