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

Constructor Details

#initialize(data, bot) ⇒ Message

Returns a new instance of Message.



249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/discordrb/data.rb', line 249

def initialize(data, bot)
  @bot = bot
  @content = data['content']
  @author = User.new(data['author'], bot)
  @channel = bot.channel(data['channel_id'].to_i)
  @timestamp = Time.at(data['timestamp'].to_i)
  @id = data['id'].to_i

  @mentions = []

  data['mentions'].each do |element|
    @mentions << User.new(element, bot)
  end
end

Instance Attribute Details

#authorObject (readonly) Also known as: user

Returns the value of attribute author.



245
246
247
# File 'lib/discordrb/data.rb', line 245

def author
  @author
end

#channelObject (readonly)

Returns the value of attribute channel.



245
246
247
# File 'lib/discordrb/data.rb', line 245

def channel
  @channel
end

#contentObject (readonly) Also known as: text

Returns the value of attribute content.



245
246
247
# File 'lib/discordrb/data.rb', line 245

def content
  @content
end

#idObject (readonly)

Returns the value of attribute id.



245
246
247
# File 'lib/discordrb/data.rb', line 245

def id
  @id
end

#mentionsObject (readonly)

Returns the value of attribute mentions.



245
246
247
# File 'lib/discordrb/data.rb', line 245

def mentions
  @mentions
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



245
246
247
# File 'lib/discordrb/data.rb', line 245

def timestamp
  @timestamp
end

Instance Method Details

#deleteObject



272
273
274
# File 'lib/discordrb/data.rb', line 272

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

#edit(new_content) ⇒ Object



268
269
270
# File 'lib/discordrb/data.rb', line 268

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

#reply(content) ⇒ Object



264
265
266
# File 'lib/discordrb/data.rb', line 264

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