Class: Discordrb::Message

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

Overview

A message on Discord that was sent to a text channel

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorUser (readonly) Also known as: user

Returns the user that sent this message.

Returns:

  • (User)

    the user that sent this message.



670
671
672
# File 'lib/discordrb/data.rb', line 670

def author
  @author
end

#channelChannel (readonly)

Returns the channel in which this message was sent.

Returns:

  • (Channel)

    the channel in which this message was sent.



673
674
675
# File 'lib/discordrb/data.rb', line 673

def channel
  @channel
end

#contentString (readonly) Also known as: text, to_s

Returns the content of this message.

Returns:

  • (String)

    the content of this message.



667
668
669
# File 'lib/discordrb/data.rb', line 667

def content
  @content
end

#idInteger (readonly) Also known as: resolve_id

Returns the ID used to uniquely identify this message.

Returns:

  • (Integer)

    the ID used to uniquely identify this message.



679
680
681
# File 'lib/discordrb/data.rb', line 679

def id
  @id
end

#mentionsArray<User> (readonly)

Returns the users that were mentioned in this message.

Returns:

  • (Array<User>)

    the users that were mentioned in this message.



682
683
684
# File 'lib/discordrb/data.rb', line 682

def mentions
  @mentions
end

#timestampTime (readonly)

Returns the timestamp at which this message was sent.

Returns:

  • (Time)

    the timestamp at which this message was sent.



676
677
678
# File 'lib/discordrb/data.rb', line 676

def timestamp
  @timestamp
end

Instance Method Details

#==(other) ⇒ Object

ID based comparison



706
707
708
# File 'lib/discordrb/data.rb', line 706

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

#await(key, attributes = {}, &block) ⇒ Object

Add an Await for a message with the same user and channel.

See Also:



729
730
731
# File 'lib/discordrb/data.rb', line 729

def await(key, attributes = {}, &block)
  @bot.add_await(key, Discordrb::Events::MessageEvent, { from: @author.id, in: @channel.id }.merge(attributes), &block)
end

#deleteObject

Deletes this message.



723
724
725
# File 'lib/discordrb/data.rb', line 723

def delete
  API.delete_message(@bot.token, @channel.id, @id)
end

#edit(new_content) ⇒ Object

Edits this message to have the specified content instead.

Parameters:

  • new_content (String)

    the new content the message should have.



718
719
720
# File 'lib/discordrb/data.rb', line 718

def edit(new_content)
  API.edit_message(@bot.token, @channel.id, @id, new_content)
end

#from_bot?true, false

Returns whether this message was sent by the current Bot.

Returns:

  • (true, false)

    whether this message was sent by the current Bot.



734
735
736
# File 'lib/discordrb/data.rb', line 734

def from_bot?
  @author.bot?
end

#reply(content) ⇒ Object

Replies to this message with the specified content.



712
713
714
# File 'lib/discordrb/data.rb', line 712

def reply(content)
  @channel.send_message(content)
end