Class: Discordrb::Reaction

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/data.rb

Overview

A reaction to a message

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Reaction

Returns a new instance of Reaction.


2402
2403
2404
2405
2406
2407
# File 'lib/discordrb/data.rb', line 2402

def initialize(data)
  @count = data['count']
  @me = data['me']
  @id = data['emoji']['id'].nil? ? nil : data['emoji']['id'].to_i
  @name = data['emoji']['name']
end

Instance Attribute Details

#countInteger (readonly)

Returns the amount of users who have reacted with this reaction.

Returns:

  • (Integer)

    the amount of users who have reacted with this reaction


2390
2391
2392
# File 'lib/discordrb/data.rb', line 2390

def count
  @count
end

#idInteger (readonly)

Returns the ID of the emoji, if it was custom.

Returns:

  • (Integer)

    the ID of the emoji, if it was custom


2397
2398
2399
# File 'lib/discordrb/data.rb', line 2397

def id
  @id
end

#metrue, false (readonly) Also known as: me?

Returns whether the current bot or user used this reaction.

Returns:

  • (true, false)

    whether the current bot or user used this reaction


2393
2394
2395
# File 'lib/discordrb/data.rb', line 2393

def me
  @me
end

#nameString (readonly)

Returns the name or unicode representation of the emoji.

Returns:

  • (String)

    the name or unicode representation of the emoji


2400
2401
2402
# File 'lib/discordrb/data.rb', line 2400

def name
  @name
end

Instance Method Details

#to_sString

Converts this Reaction into a string that can be sent back to Discord in other reaction endpoints. If ID is present, it will be rendered into the form of name:id.

Returns:

  • (String)

    the name of this reaction, including the ID if it is a custom emoji


2412
2413
2414
# File 'lib/discordrb/data.rb', line 2412

def to_s
  id.nil? ? name : "#{name}:#{id}"
end