class Discordrb::Events::MessageEvent
Event
raised when a text message is sent to a channel
Attributes
@return [File] the file that have been saved by calls to {#attach_file} and will be sent to Discord upon completion.
@return [Message] the message which triggered this event.
@return [String] the message that has been saved by calls to {#<<} and will be sent to Discord upon completion.
Public Class Methods
# File lib/discordrb/events/message.rb, line 107 def initialize(message, bot) @bot = bot @message = message @channel = message.channel @saved_message = '' @file = nil end
Public Instance Methods
Attaches a file to the message event and converts the message into a caption. @param file [File] The file to be attached
# File lib/discordrb/events/message.rb, line 130 def attach_file(file) raise ArgumentError, 'Argument is not a file!' unless file.is_a?(File) @file = file nil end
Detaches a file from the message event.
# File lib/discordrb/events/message.rb, line 138 def detach_file @file = nil end
@return [true, false] whether or not this message was sent by the bot itself
# File lib/discordrb/events/message.rb, line 143 def from_bot? @message.user.id == @bot.profile.id end
Sends file with a caption to the channel this message was sent in, right now. It is usually preferable to use {#<<} and {#attach_file} instead because it avoids rate limiting problems @param file [File] The file to send to the channel @param caption [String] The caption attached to the file @return [Discordrb::Message] the message that was sent @example Send a file from disk
event.send_file(File.open('rubytaco.png', 'r'))
# File lib/discordrb/events/message.rb, line 123 def send_file(file, caption: nil) @message.channel.send_file(file, caption: caption) end
Utility method to get the voice bot for the current server @return [VoiceBot, nil] the voice bot connected to this message's server, or nil if there is none connected
# File lib/discordrb/events/message.rb, line 149 def voice @bot.voice(@message.channel.server.id) end