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.



420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/discordrb/data.rb', line 420

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.parse(data['timestamp'])
  @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.



416
417
418
# File 'lib/discordrb/data.rb', line 416

def author
  @author
end

#channelObject (readonly)

Returns the value of attribute channel.



416
417
418
# File 'lib/discordrb/data.rb', line 416

def channel
  @channel
end

#contentObject (readonly) Also known as: text

Returns the value of attribute content.



416
417
418
# File 'lib/discordrb/data.rb', line 416

def content
  @content
end

#idObject (readonly)

Returns the value of attribute id.



416
417
418
# File 'lib/discordrb/data.rb', line 416

def id
  @id
end

#mentionsObject (readonly)

Returns the value of attribute mentions.



416
417
418
# File 'lib/discordrb/data.rb', line 416

def mentions
  @mentions
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



416
417
418
# File 'lib/discordrb/data.rb', line 416

def timestamp
  @timestamp
end

Instance Method Details

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

Add an await for a message with the same user and channel



448
449
450
# File 'lib/discordrb/data.rb', line 448

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

#deleteObject



443
444
445
# File 'lib/discordrb/data.rb', line 443

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

#edit(new_content) ⇒ Object



439
440
441
# File 'lib/discordrb/data.rb', line 439

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

#from_bot?Boolean

Returns:

  • (Boolean)


452
453
454
# File 'lib/discordrb/data.rb', line 452

def from_bot?
  @author.bot?
end

#reply(content) ⇒ Object



435
436
437
# File 'lib/discordrb/data.rb', line 435

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