Module: Discordrb::IDObject
- Included in:
- Application, Attachment, Channel, Emoji, GlobalEmoji, Integration, InviteChannel, InviteServer, Light::Integration, Light::LightProfile, Light::UltraLightServer, Message, Role, Server, User
- Defined in:
- lib/discordrb/data.rb
Overview
Mixin for objects that have IDs
Instance Attribute Summary collapse
-
#id ⇒ Integer
(also: #resolve_id)
readonly
The ID which uniquely identifies this object across Discord.
Instance Method Summary collapse
-
#==(other) ⇒ Object
ID based comparison.
-
#creation_time ⇒ Time
Estimates the time this object was generated on based on the beginning of the ID.
Instance Attribute Details
#id ⇒ Integer (readonly) Also known as: resolve_id
Returns the ID which uniquely identifies this object across Discord.
71 72 73 |
# File 'lib/discordrb/data.rb', line 71 def id @id end |
Instance Method Details
#==(other) ⇒ Object
ID based comparison
75 76 77 |
# File 'lib/discordrb/data.rb', line 75 def ==(other) Discordrb.id_compare(@id, other) end |
#creation_time ⇒ Time
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
82 83 84 85 86 |
# File 'lib/discordrb/data.rb', line 82 def creation_time # Milliseconds ms = (@id >> 22) + DISCORD_EPOCH Time.at(ms / 1000.0) end |