Module: Discordrb::Events::Respondable
- Included in:
- MessageEvent, MessageIDEvent, ReactionEvent, ReactionRemoveAllEvent, TypingEvent
- Defined in:
- lib/discordrb/events/message.rb
Overview
Module to make sending messages easier with the presence of a text channel in an event
Instance Attribute Summary collapse
-
#channel ⇒ Channel
readonly
The channel in which this event occurred.
Instance Method Summary collapse
-
#<<(message) ⇒ Object
Adds a string to be sent after the event has finished execution.
-
#drain ⇒ Object
Drains the currently saved message, which clears it out, resulting in everything being saved before being thrown away and nothing being sent to the channel (unless there is something saved after this).
-
#drain_into(result) ⇒ String
Drains the currently saved message into a result string.
-
#send_embed(message = '', embed = nil, attachments = nil, tts = false, allowed_mentions = nil, message_reference = nil) {|embed| ... } ⇒ Message
The same as #send_message, but yields a Webhooks::Embed for easy building of embedded content inside a block.
-
#send_message(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil) ⇒ Discordrb::Message
(also: #send, #respond)
Sends a message to the channel this message was sent in, right now.
-
#send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil) ⇒ Object
(also: #send_temp)
Sends a temporary message to the channel this message was sent in, right now.
Instance Attribute Details
#channel ⇒ Channel (readonly)
Returns the channel in which this event occurred.
10 11 12 |
# File 'lib/discordrb/events/message.rb', line 10 def channel @channel end |
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)
55 56 57 58 59 |
# File 'lib/discordrb/events/message.rb', line 55 def <<() addition = "#{}\n" @saved_message = @saved_message ? @saved_message + addition : addition nil end |
#drain ⇒ Object
Drains the currently saved message, which clears it out, resulting in everything being saved before being thrown away and nothing being sent to the channel (unless there is something saved after this).
64 65 66 67 |
# File 'lib/discordrb/events/message.rb', line 64 def drain @saved_message = '' nil end |
#drain_into(result) ⇒ String
Drains the currently saved message into a result string. This prepends it before that string, clears the saved message and returns the concatenation.
73 74 75 76 77 78 79 |
# File 'lib/discordrb/events/message.rb', line 73 def drain_into(result) return if result.is_a?(Discordrb::Message) result = (@saved_message.nil? ? '' : @saved_message.to_s) + (result.nil? ? '' : result.to_s) drain result end |
#send_embed(message = '', embed = nil, attachments = nil, tts = false, allowed_mentions = nil, message_reference = nil) {|embed| ... } ⇒ Message
The same as #send_message, but yields a Webhooks::Embed for easy building of embedded content inside a block.
36 37 38 |
# File 'lib/discordrb/events/message.rb', line 36 def ( = '', = nil, = nil, tts = false, allowed_mentions = nil, = nil, &block) channel.(, , , tts, allowed_mentions, , &block) end |
#send_message(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil) ⇒ 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
21 22 23 |
# File 'lib/discordrb/events/message.rb', line 21 def (content, tts = false, = nil, = nil, allowed_mentions = nil, = nil) channel.(content, tts, , , allowed_mentions, ) end |
#send_temporary_message(content, timeout, tts = false, embed = nil, attachments = nil, allowed_mentions = nil) ⇒ Object Also known as: send_temp
Sends a temporary message to the channel this message was sent in, right now.
47 48 49 |
# File 'lib/discordrb/events/message.rb', line 47 def (content, timeout, tts = false, = nil, = nil, allowed_mentions = nil) channel.(content, timeout, tts, , , allowed_mentions) end |