Class: Discorb::User

Inherits:
DiscordModel show all
Includes:
Messageable
Defined in:
lib/discorb/user.rb

Overview

Represents a user of discord.

Direct Known Subclasses

ClientUser, Member

Defined Under Namespace

Classes: Flag

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from 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

#avatarDiscorb::Asset, Discorb::DefaultAvatar (readonly)

Returns The user's avatar.

Returns:



20
21
22
# File 'lib/discorb/user.rb', line 20

def avatar
  @avatar
end

#botBoolean (readonly) Also known as: bot?

Returns Whether the user is a bot.

Returns:

  • (Boolean)

    Whether the user is a bot.



22
23
24
# File 'lib/discorb/user.rb', line 22

def bot
  @bot
end

#created_atTime (readonly)

Returns The time the user was created.

Returns:

  • (Time)

    The time the user was created.



25
26
27
# File 'lib/discorb/user.rb', line 25

def created_at
  @created_at
end

#discriminatorString (readonly)

Returns The user's discriminator.

Returns:

  • (String)

    The user's discriminator.



18
19
20
# File 'lib/discorb/user.rb', line 18

def discriminator
  @discriminator
end

#flagDiscorb::User::Flag (readonly)

Returns The user's flags.

Returns:



16
17
18
# File 'lib/discorb/user.rb', line 16

def flag
  @flag
end

#idDiscorb::Snowflake (readonly)

Returns The user's ID.

Returns:



14
15
16
# File 'lib/discorb/user.rb', line 14

def id
  @id
end

#mentionString (readonly)

Returns The user's mention.

Returns:

  • (String)

    The user's mention.



# File 'lib/discorb/user.rb', line 29

#usernameString (readonly) Also known as: name

Returns The user's username.

Returns:

  • (String)

    The user's username.



11
12
13
# File 'lib/discorb/user.rb', line 11

def username
  @username
end

#verifiedBoolean (readonly)

Returns Whether the user is verified.

Returns:

  • (Boolean)

    Whether the user is verified.



9
10
11
# File 'lib/discorb/user.rb', line 9

def verified
  @verified
end

Instance Method Details

#bot_owner?(strict: false) ⇒ Async::Task<Boolean> Also known as: app_owner?

Whether the user is a owner of the client.

Parameters:

  • strict (Boolean) (defaults to: false)

    Whether don't allow if the user is a member of the team.

Returns:

  • (Async::Task<Boolean>)

    Whether the user is a owner of the client.



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/discorb/user.rb', line 73

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

#inspectObject



61
62
63
# File 'lib/discorb/user.rb', line 61

def inspect
  "#<#{self.class} #{self}>"
end

#to_sString Also known as: to_s_user

Format the user as Username#Discriminator style.

Returns:

  • (String)

    The formatted username.



51
52
53
# File 'lib/discorb/user.rb', line 51

def to_s
  "#{@username}##{@discriminator}"
end