Class: Discordrb::Events::MessageEvent
- Includes:
- Respondable
- Defined in:
- lib/discordrb/events/message.rb
Overview
Event raised when a text message is sent to a channel
Direct Known Subclasses
Commands::CommandEvent, MentionEvent, MessageEditEvent, PrivateMessageEvent
Instance Attribute Summary collapse
-
#author ⇒ Member, User
(also: #user)
readonly
Who sent this message.
-
#channel ⇒ Channel
readonly
The channel in which this message was sent.
-
#content ⇒ String
(also: #text)
readonly
The message's content.
-
#file ⇒ File
readonly
The file that have been saved by calls to #attach_file and will be sent to Discord upon completion.
-
#message ⇒ Message
readonly
The message which triggered this event.
-
#saved_message ⇒ String
readonly
The message that has been saved by calls to Respondable#<< and will be sent to Discord upon completion.
-
#server ⇒ Server?
readonly
The server where this message was sent, or nil if it was sent in PM.
-
#timestamp ⇒ Time
readonly
The time at which the message was sent.
Attributes inherited from Event
Instance Method Summary collapse
-
#attach_file(file) ⇒ Object
Attaches a file to the message event and converts the message into a caption.
-
#detach_file ⇒ Object
Detaches a file from the message event.
-
#from_bot? ⇒ true, false
Whether or not this message was sent by the bot itself.
-
#initialize(message, bot) ⇒ MessageEvent
constructor
A new instance of MessageEvent.
-
#send_file(file, caption: nil) ⇒ Discordrb::Message
Sends file with a caption to the channel this message was sent in, right now.
-
#send_message(content) ⇒ Discordrb::Message
Sends a message to the channel this message was sent in, right now.
-
#voice ⇒ VoiceBot?
Utility method to get the voice bot for the current server.
Methods included from Respondable
#<<, #drain, #drain_into, #send_temporary_message
Constructor Details
#initialize(message, bot) ⇒ MessageEvent
Returns a new instance of MessageEvent.
94 95 96 97 98 99 100 |
# File 'lib/discordrb/events/message.rb', line 94 def initialize(, bot) @bot = bot @message = @channel = .channel @saved_message = '' @file = nil end |
Instance Attribute Details
#author ⇒ Member, User (readonly) Also known as: user
Returns who sent this message.
87 |
# File 'lib/discordrb/events/message.rb', line 87 delegate :author, :channel, :content, :timestamp, to: :message |
#channel ⇒ Channel (readonly)
Returns the channel in which this message was sent.
87 |
# File 'lib/discordrb/events/message.rb', line 87 delegate :author, :channel, :content, :timestamp, to: :message |
#content ⇒ String (readonly) Also known as: text
Returns the message's content.
87 |
# File 'lib/discordrb/events/message.rb', line 87 delegate :author, :channel, :content, :timestamp, to: :message |
#file ⇒ File (readonly)
Returns the file that have been saved by calls to #attach_file and will be sent to Discord upon completion.
73 74 75 |
# File 'lib/discordrb/events/message.rb', line 73 def file @file end |
#message ⇒ Message (readonly)
Returns the message which triggered this event.
67 68 69 |
# File 'lib/discordrb/events/message.rb', line 67 def @message end |
#saved_message ⇒ String (readonly)
Returns the message that has been saved by calls to Respondable#<< and will be sent to Discord upon completion.
70 71 72 |
# File 'lib/discordrb/events/message.rb', line 70 def @saved_message end |
#server ⇒ Server? (readonly)
Returns the server where this message was sent, or nil if it was sent in PM.
92 |
# File 'lib/discordrb/events/message.rb', line 92 delegate :server, to: :channel |
#timestamp ⇒ Time (readonly)
Returns the time at which the message was sent.
87 |
# File 'lib/discordrb/events/message.rb', line 87 delegate :author, :channel, :content, :timestamp, to: :message |
Instance Method Details
#attach_file(file) ⇒ Object
Attaches a file to the message event and converts the message into a caption.
123 124 125 126 127 |
# File 'lib/discordrb/events/message.rb', line 123 def attach_file(file) raise ArgumentError, 'Argument is not a file!' unless file.is_a?(File) @file = file nil end |
#detach_file ⇒ Object
Detaches a file from the message event.
130 131 132 133 |
# File 'lib/discordrb/events/message.rb', line 130 def detach_file @file = nil nil end |
#from_bot? ⇒ true, false
Returns whether or not this message was sent by the bot itself.
136 137 138 |
# File 'lib/discordrb/events/message.rb', line 136 def from_bot? @message.user.id == @bot.profile.id end |
#send_file(file, caption: 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
116 117 118 |
# File 'lib/discordrb/events/message.rb', line 116 def send_file(file, caption: nil) @message.channel.send_file(file, caption: ) end |
#send_message(content) ⇒ Discordrb::Message
Sends a message to the channel this message was sent in, right now. It is usually preferable to use Respondable#<< instead because it avoids rate limiting problems
106 107 108 |
# File 'lib/discordrb/events/message.rb', line 106 def (content) @message.channel.(content) end |
#voice ⇒ VoiceBot?
Utility method to get the voice bot for the current server
142 143 144 |
# File 'lib/discordrb/events/message.rb', line 142 def voice @bot.voice(@message.channel.server.id) end |