module Discordrb::Events::Respondable

Module to make sending messages easier with the presence of a text channel in an event

Attributes

channel[R]

@return [Channel] the channel in which this event occurred

Public Instance Methods

<<(message) click to toggle source

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) @param message [String] The message to send to the channel

# File lib/discordrb/events/message.rb, line 44
def <<(message)
  addition = "#{message}\n"
  @saved_message = @saved_message ? @saved_message + addition : addition
  nil
end
drain() click to toggle source

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). @see <<

# File lib/discordrb/events/message.rb, line 53
def drain
  @saved_message = ''
  nil
end
drain_into(result) click to toggle source

Drains the currently saved message into a result string. This prepends it before that string, clears the saved message and returns the concatenation. @param result [String] The result string to drain into. @return [String] a string formed by concatenating the saved message and the argument.

# File lib/discordrb/events/message.rb, line 62
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
respond(content, tts = false, embed = nil)
Alias for: send_message
send(content, tts = false, embed = nil)
Alias for: send_message
send_embed(message = '', embed = nil, &block) click to toggle source

The same as {#send_message}, but yields a {Webhooks::Embed} for easy building of embedded content inside a block. @see Channel#send_embed @param message [String] The message that should be sent along with the embed. If this is the empty string, only the embed will be shown. @param embed [Discordrb::Webhooks::Embed, nil] The embed to start the building process with, or nil if one should be created anew. @yield [embed] Yields the embed to allow for easy building inside a block. @yieldparam embed [Discordrb::Webhooks::Embed] The embed from the parameters, or a new one. @return [Message] The resulting message.

# File lib/discordrb/events/message.rb, line 29
def send_embed(message = '', embed = nil, &block)
  channel.send_embed(message, embed, &block)
end
send_message(content, tts = false, embed = nil) click to toggle source

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 @param content [String] The message to send to the channel @param tts [true, false] Whether or not this message should be sent using Discord text-to-speech. @param embed [Hash, Discordrb::Webhooks::Embed, nil] The rich embed to append to this message. @return [Discordrb::Message] the message that was sent

# File lib/discordrb/events/message.rb, line 18
def send_message(content, tts = false, embed = nil)
  channel.send_message(content, tts, embed)
end
Also aliased as: send, respond
send_temp(content, timeout)
send_temporary_message(content, timeout) click to toggle source

Sends a temporary message to the channel this message was sent in, right now. @param content [String] The content to send. Should not be longer than 2000 characters or it will result in an error. @param timeout [Float] The amount of time in seconds after which the message sent will be deleted.

# File lib/discordrb/events/message.rb, line 36
def send_temporary_message(content, timeout)
  channel.send_temporary_message(content, timeout)
end
Also aliased as: send_temp