Class: Discorb::Message::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/discorb/message.rb

Overview

Represents reference of message.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(guild_id, channel_id, message_id, fail_if_not_exists: true) -> Reference

Initialize a new reference.

Parameters:



462
463
464
465
466
467
# File 'lib/discorb/message.rb', line 462

def initialize(guild_id, channel_id, message_id, fail_if_not_exists: true)
  @guild_id = guild_id
  @channel_id = channel_id
  @message_id = message_id
  @fail_if_not_exists = fail_if_not_exists
end

Instance Attribute Details

#channel_id -> Discorb::Snowflake

Returns The channel ID.

Returns:



446
447
448
# File 'lib/discorb/message.rb', line 446

def channel_id
  @channel_id
end

#fail_if_not_exists -> Boolean Also known as: fail_if_not_exists?

Returns Whether fail the request if the message is not found.

Returns:

  • (Boolean)

    Whether fail the request if the message is not found.



450
451
452
# File 'lib/discorb/message.rb', line 450

def fail_if_not_exists
  @fail_if_not_exists
end

#guild_id -> Discorb::Snowflake

Returns The guild ID.

Returns:



444
445
446
# File 'lib/discorb/message.rb', line 444

def guild_id
  @guild_id
end

#message_id -> Discorb::Snowflake

Returns The message ID.

Returns:



448
449
450
# File 'lib/discorb/message.rb', line 448

def message_id
  @message_id
end

Class Method Details

.from_hash(data) -> Discorb::Message::Reference

Initialize a new reference from a hash.

Parameters:

  • data (Hash)

    The hash.

Returns:

See Also:



493
494
495
# File 'lib/discorb/message.rb', line 493

def self.from_hash(data)
  new(data[:guild_id], data[:channel_id], data[:message_id], fail_if_not_exists: data[:fail_if_not_exists])
end

Instance Method Details

#to_hash -> Hash Also known as: to_reference

Convert the reference to a hash.

Returns:

  • (Hash)

    The hash.



474
475
476
477
478
479
480
481
# File 'lib/discorb/message.rb', line 474

def to_hash
  {
    message_id: @message_id,
    channel_id: @channel_id,
    guild_id: @guild_id,
    fail_if_not_exists: @fail_if_not_exists,
  }
end