Class: Discordrb::Message

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

Overview

A message on Discord that was sent to a text channel

Instance Attribute Summary collapse

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from IDObject

#==, #creation_time

Instance Attribute Details

#attachmentsArray<Attachment> (readonly)

Returns the files attached to this message.

Returns:

  • (Array<Attachment>)

    the files attached to this message.



1031
1032
1033
# File 'lib/discordrb/data.rb', line 1031

def attachments
  @attachments
end

#authorMember (readonly) Also known as: user

Returns the user that sent this message.

Returns:

  • (Member)

    the user that sent this message.



1019
1020
1021
# File 'lib/discordrb/data.rb', line 1019

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.



1022
1023
1024
# File 'lib/discordrb/data.rb', line 1022

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.



1016
1017
1018
# File 'lib/discordrb/data.rb', line 1016

def content
  @content
end

#mentionsArray<User> (readonly)

Returns the users that were mentioned in this message.

Returns:

  • (Array<User>)

    the users that were mentioned in this message.



1028
1029
1030
# File 'lib/discordrb/data.rb', line 1028

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.



1025
1026
1027
# File 'lib/discordrb/data.rb', line 1025

def timestamp
  @timestamp
end

Instance Method Details

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

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

See Also:



1088
1089
1090
# File 'lib/discordrb/data.rb', line 1088

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.



1081
1082
1083
1084
# File 'lib/discordrb/data.rb', line 1081

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

#edit(new_content) ⇒ Message

Edits this message to have the specified content instead.

Parameters:

  • new_content (String)

    the new content the message should have.

Returns:

  • (Message)

    the resulting message.



1075
1076
1077
1078
# File 'lib/discordrb/data.rb', line 1075

def edit(new_content)
  response = API.edit_message(@bot.token, @channel.id, @id, new_content)
  Message.new(JSON.parse(response), @bot)
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.



1093
1094
1095
# File 'lib/discordrb/data.rb', line 1093

def from_bot?
  @author && @author.current_bot?
end

#inspectObject

The inspect method is overwritten to give more useful output



1098
1099
1100
# File 'lib/discordrb/data.rb', line 1098

def inspect
  "<Message content=\"#{@content}\" id=#{@id} timestamp=#{@timestamp} author=#{@author} channel=#{@channel}>"
end

#reply(content) ⇒ Object

Replies to this message with the specified content.



1068
1069
1070
# File 'lib/discordrb/data.rb', line 1068

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