Class: Discordrb::Events::MessageEvent
- 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 ⇒ 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.
-
#message ⇒ Message
readonly
The message which triggered this event.
-
#saved_message ⇒ String
readonly
The message that has been saved by calls to #<< 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
-
#<<(message) ⇒ Object
Adds a string to be sent after the event has finished execution.
-
#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_message(content) ⇒ Discordrb::Message
(also: #send, #respond)
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.
Constructor Details
#initialize(message, bot) ⇒ MessageEvent
Returns a new instance of MessageEvent.
33 34 35 36 37 |
# File 'lib/discordrb/events/message.rb', line 33 def initialize(, bot) @bot = bot @message = @saved_message = '' end |
Instance Attribute Details
#author ⇒ User (readonly) Also known as: user
Returns who sent this message.
26 |
# File 'lib/discordrb/events/message.rb', line 26 delegate :author, :channel, :content, :timestamp, to: :message |
#channel ⇒ Channel (readonly)
Returns the channel in which this message was sent.
26 |
# File 'lib/discordrb/events/message.rb', line 26 delegate :author, :channel, :content, :timestamp, to: :message |
#content ⇒ String (readonly) Also known as: text
Returns the message's content.
26 |
# File 'lib/discordrb/events/message.rb', line 26 delegate :author, :channel, :content, :timestamp, to: :message |
#message ⇒ Message (readonly)
Returns the message which triggered this event.
9 10 11 |
# File 'lib/discordrb/events/message.rb', line 9 def @message end |
#saved_message ⇒ String (readonly)
Returns the message that has been saved by calls to #<< and will be sent to Discord upon completion.
12 13 14 |
# File 'lib/discordrb/events/message.rb', line 12 def @saved_message end |
#server ⇒ Server? (readonly)
Returns the server where this message was sent, or nil if it was sent in PM.
31 |
# File 'lib/discordrb/events/message.rb', line 31 delegate :server, to: :channel |
#timestamp ⇒ Time (readonly)
Returns the time at which the message was sent.
26 |
# File 'lib/discordrb/events/message.rb', line 26 delegate :author, :channel, :content, :timestamp, to: :message |
Instance Method Details
#<<(message) ⇒ Object
Adds a string to be sent after the event has finished execution. Avoids problems with rate limiting because only one message is ever sent. If it is used multiple times, the strings will bunch up into one message (separated by newlines)
62 63 64 65 |
# File 'lib/discordrb/events/message.rb', line 62 def <<() @saved_message += "#{}\n" nil end |
#from_bot? ⇒ true, false
Returns whether or not this message was sent by the bot itself.
48 49 50 |
# File 'lib/discordrb/events/message.rb', line 48 def from_bot? @message.user.id == @bot.profile.id end |
#send_message(content) ⇒ Discordrb::Message Also known as: send, respond
Sends a message to the channel this message was sent in, right now. It is usually preferable to use #<< instead because it avoids rate limiting problems
43 44 45 |
# File 'lib/discordrb/events/message.rb', line 43 def (content) @message.channel.(content) end |
#voice ⇒ VoiceBot?
Utility method to get the voice bot for the current server
54 55 56 |
# File 'lib/discordrb/events/message.rb', line 54 def voice @bot.voice(@message.channel.server.id) end |