Class: Discordrb::User
- Inherits:
 - 
      Object
      
        
- Object
 - Discordrb::User
 
 
- Includes:
 - IDObject, UserAttributes
 
- Defined in:
 - lib/discordrb/data/user.rb
 
Overview
User on Discord, including internal data like discriminators
Constant Summary
Constants included from UserAttributes
Discordrb::UserAttributes::FLAGS
Instance Attribute Summary collapse
- 
  
    
      #activities  ⇒ ActivitySet 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The activities of the user.
 - 
  
    
      #client_status  ⇒ Hash<Symbol, Symbol> 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The current online status (
:online,:idleor:dnd) of the user on various device types (:desktop,:mobile, or:web). - 
  
    
      #status  ⇒ Symbol 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The current online status of the user (
:online,:offlineor:idle). 
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
- 
  
    
      #await(key, attributes = {}, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Add an await for a message from this user.
 - 
  
    
      #await!(attributes = {}, &block)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Add a blocking await for a message from this user.
 - 
  
    
      #banner_id  ⇒ String? 
    
    
  
  
  
  
  
  
  
  
  
    
The ID of this user's current banner, can be used to generate a banner URL.
 - 
  
    
      #current_bot?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Is the user the bot?.
 - 
  
    
      #dnd?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Whether this user is set to do not disturb.
 - 
  
    
      #game  ⇒ String? 
    
    
  
  
  
  
  
  
  deprecated
  
  
    Deprecated. 
Please use ActivitySet#games for information about the user's game activity
 - 
  
    
      #idle?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Whether this user is idle.
 - 
  
    
      #inspect  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
The inspect method is overwritten to give more useful output.
 - 
  
    
      #offline?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Whether this user is offline.
 - 
  
    
      #on(server)  ⇒ Member 
    
    
  
  
  
  
  
  
  
  
  
    
Gets the member this user is on a server.
 - 
  
    
      #online?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Whether this user is online.
 - 
  
    
      #pm(content = nil)  ⇒ Object 
    
    
      (also: #dm)
    
  
  
  
  
  
  
  
  
  
    
Get a user's PM channel or send them a PM.
 - 
  
    
      #send_file(file, caption = nil, filename: nil, spoiler: nil)  ⇒ Message 
    
    
  
  
  
  
  
  
  
  
  
    
Send the user a file.
 - 
  
    
      #stream_type  ⇒ Integer 
    
    
  
  
  
  
  
  
  deprecated
  
  
    Deprecated. 
Please use ActivitySet#streaming for information about the user's stream activity
 - 
  
    
      #stream_url  ⇒ String? 
    
    
  
  
  
  
  
  
  deprecated
  
  
    Deprecated. 
Please use ActivitySet#streaming for information about the user's stream activity
 
Methods included from UserAttributes
#avatar_url, #banner_url, #display_name, #distinct, #mention
Methods included from IDObject
#==, #creation_time, synthesise
Instance Attribute Details
#activities ⇒ ActivitySet (readonly)
Returns the activities of the user.
      130 131 132  | 
    
      # File 'lib/discordrb/data/user.rb', line 130 def activities @activities end  | 
  
#client_status ⇒ Hash<Symbol, Symbol> (readonly)
Returns the current online status (:online, :idle or :dnd) of the user
on various device types (:desktop, :mobile, or :web). The value will be nil if the user is offline or invisible.
      134 135 136  | 
    
      # File 'lib/discordrb/data/user.rb', line 134 def client_status @client_status end  | 
  
#status ⇒ Symbol (readonly)
Returns the current online status of the user (:online, :offline or :idle).
      127 128 129  | 
    
      # File 'lib/discordrb/data/user.rb', line 127 def status @status end  | 
  
Instance Method Details
#await(key, attributes = {}, &block) ⇒ Object
Add an await for a message from this user. Specifically, this adds a global await for a MessageEvent with this user's ID as a :from attribute.
      247 248 249  | 
    
      # File 'lib/discordrb/data/user.rb', line 247 def await(key, attributes = {}, &block) @bot.add_await(key, Discordrb::Events::MessageEvent, { from: @id }.merge(attributes), &block) end  | 
  
#await!(attributes = {}, &block) ⇒ Object
Add a blocking await for a message from this user. Specifically, this adds a global await for a MessageEvent with this user's ID as a :from attribute.
      254 255 256  | 
    
      # File 'lib/discordrb/data/user.rb', line 254 def await!(attributes = {}, &block) @bot.add_await!(Discordrb::Events::MessageEvent, { from: @id }.merge(attributes), &block) end  | 
  
#banner_id ⇒ String?
Returns the ID of this user's current banner, can be used to generate a banner URL.
      195 196 197  | 
    
      # File 'lib/discordrb/data/user.rb', line 195 def @banner_id ||= JSON.parse(API::User.resolve(@bot.token, @id))['banner'] end  | 
  
#current_bot? ⇒ true, false
Is the user the bot?
      268 269 270  | 
    
      # File 'lib/discordrb/data/user.rb', line 268 def current_bot? @bot.profile.id == @id end  | 
  
#dnd? ⇒ true, false
Returns whether this user is set to do not disturb.
      295 296 297 298 299  | 
    
      # File 'lib/discordrb/data/user.rb', line 295 %i[offline idle online dnd].each do |e| define_method("#{e}?") do @status.to_sym == e end end  | 
  
#game ⇒ String?
Please use ActivitySet#games for information about the user's game activity
Returns the game the user is currently playing, or nil if nothing is being played.
      303 304 305  | 
    
      # File 'lib/discordrb/data/user.rb', line 303 def game @activities.games.first&.name end  | 
  
#idle? ⇒ true, false
Returns whether this user is idle.
      295 296 297 298 299  | 
    
      # File 'lib/discordrb/data/user.rb', line 295 %i[offline idle online dnd].each do |e| define_method("#{e}?") do @status.to_sym == e end end  | 
  
#inspect ⇒ Object
The inspect method is overwritten to give more useful output
      320 321 322  | 
    
      # File 'lib/discordrb/data/user.rb', line 320 def inspect "<User username=#{@username} id=#{@id} discriminator=#{@discriminator}>" end  | 
  
#offline? ⇒ true, false
Returns whether this user is offline.
      295 296 297 298 299  | 
    
      # File 'lib/discordrb/data/user.rb', line 295 %i[offline idle online dnd].each do |e| define_method("#{e}?") do @status.to_sym == e end end  | 
  
#on(server) ⇒ Member
Gets the member this user is on a server
      261 262 263 264  | 
    
      # File 'lib/discordrb/data/user.rb', line 261 def on(server) id = server.resolve_id @bot.server(id).member(@id) end  | 
  
#online? ⇒ true, false
Returns whether this user is online.
      295 296 297 298 299  | 
    
      # File 'lib/discordrb/data/user.rb', line 295 %i[offline idle online dnd].each do |e| define_method("#{e}?") do @status.to_sym == e end end  | 
  
#pm ⇒ Channel #pm(content) ⇒ Message Also known as: dm
Get a user's PM channel or send them a PM
      168 169 170 171 172 173 174 175 176 177  | 
    
      # File 'lib/discordrb/data/user.rb', line 168 def pm(content = nil) if content # Recursively call pm to get the channel, then send a message to it channel = pm channel.(content) else # If no message was specified, return the PM channel @bot.pm_channel(@id) end end  | 
  
#send_file(file, caption = nil, filename: nil, spoiler: nil) ⇒ Message
Send the user a file.
      189 190 191  | 
    
      # File 'lib/discordrb/data/user.rb', line 189 def send_file(file, caption = nil, filename: nil, spoiler: nil) pm.send_file(file, caption: caption, filename: filename, spoiler: spoiler) end  | 
  
#stream_type ⇒ Integer
Please use ActivitySet#streaming for information about the user's stream activity
Returns 1 for twitch streams, or 0 for no stream.
      309 310 311  | 
    
      # File 'lib/discordrb/data/user.rb', line 309 def stream_type @activities.streaming ? 1 : 0 end  | 
  
#stream_url ⇒ String?
Please use ActivitySet#streaming for information about the user's stream activity
Returns the URL to the stream, if the user is currently streaming something.
      315 316 317  | 
    
      # File 'lib/discordrb/data/user.rb', line 315 def stream_url @activities.streaming.first&.url end  |