Module: Discordrb::IDObject

Overview

Mixin for objects that have IDs

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idInteger (readonly) Also known as: resolve_id

Returns the ID which uniquely identifies this object across Discord.

Returns:

  • (Integer)

    the ID which uniquely identifies this object across Discord.



67
68
69
# File 'lib/discordrb/data.rb', line 67

def id
  @id
end

Instance Method Details

#==(other) ⇒ Object

ID based comparison



71
72
73
# File 'lib/discordrb/data.rb', line 71

def ==(other)
  Discordrb.id_compare(@id, other)
end

#creation_timeTime

Estimates the time this object was generated on based on the beginning of the ID. This is fairly accurate but shouldn't be relied on as Discord might change its algorithm at any time

Returns:

  • (Time)

    when this object was created at



78
79
80
81
82
# File 'lib/discordrb/data.rb', line 78

def creation_time
  # Milliseconds
  ms = (@id >> 22) + DISCORD_EPOCH
  Time.at(ms / 1000.0)
end