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)



1000
1001
1002
# File 'lib/discordrb/data.rb', line 1000

def attachments
  @attachments
end

#authorMember (readonly) Also known as: user



988
989
990
# File 'lib/discordrb/data.rb', line 988

def author
  @author
end

#channelChannel (readonly)



991
992
993
# File 'lib/discordrb/data.rb', line 991

def channel
  @channel
end

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



985
986
987
# File 'lib/discordrb/data.rb', line 985

def content
  @content
end

#mentionsArray<User> (readonly)



997
998
999
# File 'lib/discordrb/data.rb', line 997

def mentions
  @mentions
end

#timestampTime (readonly)



994
995
996
# File 'lib/discordrb/data.rb', line 994

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:



1057
1058
1059
# File 'lib/discordrb/data.rb', line 1057

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.



1050
1051
1052
1053
# File 'lib/discordrb/data.rb', line 1050

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.



1044
1045
1046
1047
# File 'lib/discordrb/data.rb', line 1044

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



1062
1063
1064
# File 'lib/discordrb/data.rb', line 1062

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

#inspectObject

The inspect method is overwritten to give more useful output



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

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.



1037
1038
1039
# File 'lib/discordrb/data.rb', line 1037

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