Class: Discordrb::Events::MessageEvent

Inherits:
Event
  • Object
show all
Includes:
Respondable
Defined in:
lib/discordrb/events/message.rb

Overview

Event raised when a text message is sent to a channel

Instance Attribute Summary collapse

Attributes inherited from Event

#bot

Instance Method Summary collapse

Methods included from Respondable

#<<, #drain, #drain_into, #send_embed, #send_message, #send_message!, #send_temporary_message

Instance Attribute Details

#authorMember, User (readonly) Also known as: user

Returns who sent this message.

See Also:



132
# File 'lib/discordrb/events/message.rb', line 132

delegate :author, :channel, :content, :timestamp, to: :message

#channelChannel (readonly)

Returns the channel in which this message was sent.

See Also:



132
# File 'lib/discordrb/events/message.rb', line 132

delegate :author, :channel, :content, :timestamp, to: :message

#contentString (readonly) Also known as: text

Returns the message's content.

See Also:



132
# File 'lib/discordrb/events/message.rb', line 132

delegate :author, :channel, :content, :timestamp, to: :message

#fileFile (readonly)



112
113
114
# File 'lib/discordrb/events/message.rb', line 112

def file
  @file
end

#file_spoilertrue, false (readonly)



118
119
120
# File 'lib/discordrb/events/message.rb', line 118

def file_spoiler
  @file_spoiler
end

#filenameString (readonly)



115
116
117
# File 'lib/discordrb/events/message.rb', line 115

def filename
  @filename
end

#messageMessage (readonly)



106
107
108
# File 'lib/discordrb/events/message.rb', line 106

def message
  @message
end

#saved_messageString (readonly)



109
110
111
# File 'lib/discordrb/events/message.rb', line 109

def saved_message
  @saved_message
end

#serverServer? (readonly)

Returns the server where this message was sent, or nil if it was sent in PM.

See Also:



137
# File 'lib/discordrb/events/message.rb', line 137

delegate :server, to: :channel

#timestampTime (readonly)

Returns the time at which the message was sent.

See Also:



132
# File 'lib/discordrb/events/message.rb', line 132

delegate :author, :channel, :content, :timestamp, to: :message

Instance Method Details

#attach_file(file, filename: nil, spoiler: nil) ⇒ Object

Attaches a file to the message event and converts the message into a caption.

Raises:

  • (ArgumentError)


169
170
171
172
173
174
175
176
# File 'lib/discordrb/events/message.rb', line 169

def attach_file(file, filename: nil, spoiler: nil)
  raise ArgumentError, 'Argument is not a file!' unless file.is_a?(File)

  @file = file
  @filename = filename
  @file_spoiler = spoiler
  nil
end

#detach_fileObject

Detaches a file from the message event.



179
180
181
182
183
# File 'lib/discordrb/events/message.rb', line 179

def detach_file
  @file = nil
  @filename = nil
  @file_spoiler = nil
end

#from_bot?true, false



186
187
188
# File 'lib/discordrb/events/message.rb', line 186

def from_bot?
  @message.user.id == @bot.profile.id
end

#send_file(file, caption: nil, filename: nil, spoiler: nil) ⇒ Discordrb::Message

Sends file with a caption to the channel this message was sent in, right now. It is usually preferable to use Respondable#<< and #attach_file instead because it avoids rate limiting problems

Examples:

Send a file from disk

event.send_file(File.open('rubytaco.png', 'r'))


160
161
162
# File 'lib/discordrb/events/message.rb', line 160

def send_file(file, caption: nil, filename: nil, spoiler: nil)
  @message.channel.send_file(file, caption: caption, filename: filename, spoiler: spoiler)
end

#voiceVoiceBot?

Utility method to get the voice bot for the current server



192
193
194
# File 'lib/discordrb/events/message.rb', line 192

def voice
  @bot.voice(@message.channel.server.id)
end