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)



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

def attachments
  @attachments
end

#authorMember (readonly) Also known as: user



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

def author
  @author
end

#channelChannel (readonly)



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

def channel
  @channel
end

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



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

def content
  @content
end

#mentionsArray<User> (readonly)



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

def mentions
  @mentions
end

#timestampTime (readonly)



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.



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



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