Class: Discordrb::Message
- Inherits:
-
Object
- Object
- Discordrb::Message
- Includes:
- IDObject
- Defined in:
- lib/discordrb/data/message.rb
Overview
A message on Discord that was sent to a text channel
Constant Summary collapse
- ZERO_DISCRIM =
The discriminator that webhook user accounts have.
'0000'
Instance Attribute Summary collapse
-
#attachments ⇒ Array<Attachment>
readonly
The files attached to this message.
-
#author ⇒ Member, User
(also: #user, #writer)
readonly
The user that sent this message.
-
#channel ⇒ Channel
readonly
The channel in which this message was sent.
-
#content ⇒ String
(also: #text, #to_s)
readonly
The content of this message.
-
#edited ⇒ true, false
(also: #edited?)
readonly
Whether the message was edited or not.
-
#edited_timestamp ⇒ Time
(also: #edit_timestamp)
readonly
The timestamp at which this message was edited.
-
#embeds ⇒ Array<Embed>
readonly
The embed objects contained in this message.
-
#mention_everyone ⇒ true, false
(also: #mention_everyone?, #mentions_everyone?)
readonly
Whether the message mentioned everyone or not.
-
#mentions ⇒ Array<User>
readonly
The users that were mentioned in this message.
-
#nonce ⇒ String
readonly
Used for validating a message was sent.
-
#pinned ⇒ true, false
(also: #pinned?)
readonly
Whether the message is pinned or not.
-
#reactions ⇒ Array<Reaction>
readonly
The reaction objects contained in this message.
-
#role_mentions ⇒ Array<Role>
readonly
The roles that were mentioned in this message.
-
#server ⇒ Server?
readonly
The server in which this message was sent.
-
#timestamp ⇒ Time
readonly
The timestamp at which this message was sent.
-
#tts ⇒ true, false
(also: #tts?)
readonly
Whether the message used Text-To-Speech (TTS) or not.
-
#webhook_id ⇒ Integer?
readonly
The webhook ID that sent this message, or
nil
if it wasn't sent through a webhook.
Attributes included from IDObject
Instance Method Summary collapse
-
#await(key, attributes = {}, &block) ⇒ Object
deprecated
Deprecated.
Will be changed to blocking behavior in v4.0. Use #await! instead.
-
#await!(attributes = {}, &block) ⇒ Object
Add a blocking Await for a message with the same user and channel.
-
#create_reaction(reaction) ⇒ Object
(also: #react)
Reacts to a message.
-
#delete(reason = nil) ⇒ Object
Deletes this message.
-
#delete_all_reactions ⇒ Object
Removes all reactions from this message.
-
#delete_own_reaction(reaction) ⇒ Object
Deletes this client's reaction on this message.
-
#delete_reaction(user, reaction) ⇒ Object
Deletes a reaction made by a user on this message.
-
#edit(new_content, new_embed = nil) ⇒ Message
Edits this message to have the specified content instead.
-
#emoji ⇒ Array<Emoji>
The emotes that were used/mentioned in this message.
-
#emoji? ⇒ true, false
Check if any emoji were used in this message.
-
#from_bot? ⇒ true, false
Whether this message was sent by the current Bot.
-
#inspect ⇒ Object
The inspect method is overwritten to give more useful output.
-
#link ⇒ String
(also: #jump_link)
A URL that a user can use to navigate to this message in the client.
-
#my_reactions ⇒ Array<Reaction>
Returns the reactions made by the current bot or user.
-
#pin(reason = nil) ⇒ Object
Pins this message.
-
#reacted_with(reaction, limit: 100) ⇒ Array<User>
Returns the list of users who reacted with a certain reaction.
-
#reactions? ⇒ true, false
Check if any reactions were used in this message.
-
#referenced_message ⇒ Message?
The Message this Message was sent in reply to.
-
#reply(content) ⇒ Object
deprecated
Deprecated.
Please use #respond.
-
#reply!(content, tts: false, embed: nil, attachments: nil, allowed_mentions: {}, mention_user: false) ⇒ Message
Sends a message to this channel.
-
#reply? ⇒ true, false
Whether or not this message was sent in reply to another message.
-
#respond(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil) ⇒ Message
Sends a message to this channel.
-
#unpin(reason = nil) ⇒ Object
Unpins this message.
-
#webhook? ⇒ true, false
Whether this message has been sent over a webhook.
Methods included from IDObject
#==, #creation_time, synthesise
Instance Attribute Details
#attachments ⇒ Array<Attachment> (readonly)
Returns the files attached to this message.
36 37 38 |
# File 'lib/discordrb/data/message.rb', line 36 def @attachments end |
#author ⇒ Member, User (readonly) Also known as: user, writer
Returns the user that sent this message. (Will be a Discordrb::Member most of the time, it should only be a User for old messages when the author has left the server since then).
15 16 17 |
# File 'lib/discordrb/data/message.rb', line 15 def @author end |
#channel ⇒ Channel (readonly)
Returns the channel in which this message was sent.
20 21 22 |
# File 'lib/discordrb/data/message.rb', line 20 def channel @channel end |
#content ⇒ String (readonly) Also known as: text, to_s
Returns the content of this message.
9 10 11 |
# File 'lib/discordrb/data/message.rb', line 9 def content @content end |
#edited ⇒ true, false (readonly) Also known as: edited?
Returns whether the message was edited or not.
52 53 54 |
# File 'lib/discordrb/data/message.rb', line 52 def edited @edited end |
#edited_timestamp ⇒ Time (readonly) Also known as: edit_timestamp
Returns the timestamp at which this message was edited. nil
if the message was never edited.
26 27 28 |
# File 'lib/discordrb/data/message.rb', line 26 def @edited_timestamp end |
#embeds ⇒ Array<Embed> (readonly)
Returns the embed objects contained in this message.
39 40 41 |
# File 'lib/discordrb/data/message.rb', line 39 def @embeds end |
#mention_everyone ⇒ true, false (readonly) Also known as: mention_everyone?, mentions_everyone?
Returns whether the message mentioned everyone or not.
56 57 58 |
# File 'lib/discordrb/data/message.rb', line 56 def mention_everyone @mention_everyone end |
#mentions ⇒ Array<User> (readonly)
Returns the users that were mentioned in this message.
30 31 32 |
# File 'lib/discordrb/data/message.rb', line 30 def mentions @mentions end |
#nonce ⇒ String (readonly)
Returns used for validating a message was sent.
49 50 51 |
# File 'lib/discordrb/data/message.rb', line 49 def nonce @nonce end |
#pinned ⇒ true, false (readonly) Also known as: pinned?
Returns whether the message is pinned or not.
61 62 63 |
# File 'lib/discordrb/data/message.rb', line 61 def pinned @pinned end |
#reactions ⇒ Array<Reaction> (readonly)
Returns the reaction objects contained in this message.
42 43 44 |
# File 'lib/discordrb/data/message.rb', line 42 def reactions @reactions end |
#role_mentions ⇒ Array<Role> (readonly)
Returns the roles that were mentioned in this message.
33 34 35 |
# File 'lib/discordrb/data/message.rb', line 33 def role_mentions @role_mentions end |
#server ⇒ Server? (readonly)
Returns the server in which this message was sent.
65 66 67 |
# File 'lib/discordrb/data/message.rb', line 65 def server @server end |
#timestamp ⇒ Time (readonly)
Returns the timestamp at which this message was sent.
23 24 25 |
# File 'lib/discordrb/data/message.rb', line 23 def @timestamp end |
#tts ⇒ true, false (readonly) Also known as: tts?
Returns whether the message used Text-To-Speech (TTS) or not.
45 46 47 |
# File 'lib/discordrb/data/message.rb', line 45 def tts @tts end |
#webhook_id ⇒ Integer? (readonly)
Returns the webhook ID that sent this message, or nil
if it wasn't sent through a webhook.
68 69 70 |
# File 'lib/discordrb/data/message.rb', line 68 def webhook_id @webhook_id end |
Instance Method Details
#await(key, attributes = {}, &block) ⇒ Object
215 216 217 |
# File 'lib/discordrb/data/message.rb', line 215 def await(key, attributes = {}, &block) @bot.add_await(key, Discordrb::Events::MessageEvent, { from: @author.id, in: @channel.id }.merge(attributes), &block) end |
#await!(attributes = {}, &block) ⇒ Object
Add a blocking Await for a message with the same user and channel.
221 222 223 |
# File 'lib/discordrb/data/message.rb', line 221 def await!(attributes = {}, &block) @bot.add_await!(Discordrb::Events::MessageEvent, { from: @author.id, in: @channel.id }.merge(attributes), &block) end |
#create_reaction(reaction) ⇒ Object Also known as: react
Reacts to a message.
263 264 265 266 267 |
# File 'lib/discordrb/data/message.rb', line 263 def create_reaction(reaction) reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction) API::Channel.create_reaction(@bot.token, @channel.id, @id, reaction) nil end |
#delete(reason = nil) ⇒ Object
Deletes this message.
193 194 195 196 |
# File 'lib/discordrb/data/message.rb', line 193 def delete(reason = nil) API::Channel.(@bot.token, @channel.id, @id, reason) nil end |
#delete_all_reactions ⇒ Object
Removes all reactions from this message.
303 304 305 |
# File 'lib/discordrb/data/message.rb', line 303 def delete_all_reactions API::Channel.delete_all_reactions(@bot.token, @channel.id, @id) end |
#delete_own_reaction(reaction) ⇒ Object
Deletes this client's reaction on this message.
297 298 299 300 |
# File 'lib/discordrb/data/message.rb', line 297 def delete_own_reaction(reaction) reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction) API::Channel.delete_own_reaction(@bot.token, @channel.id, @id, reaction) end |
#delete_reaction(user, reaction) ⇒ Object
Deletes a reaction made by a user on this message.
290 291 292 293 |
# File 'lib/discordrb/data/message.rb', line 290 def delete_reaction(user, reaction) reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction) API::Channel.delete_user_reaction(@bot.token, @channel.id, @id, reaction, user.resolve_id) end |
#edit(new_content, new_embed = nil) ⇒ Message
Edits this message to have the specified content instead. You can only edit your own messages.
187 188 189 190 |
# File 'lib/discordrb/data/message.rb', line 187 def edit(new_content, = nil) response = API::Channel.(@bot.token, @channel.id, @id, new_content, [], ? .to_hash : nil) Message.new(JSON.parse(response), @bot) end |
#emoji ⇒ Array<Emoji>
Returns the emotes that were used/mentioned in this message.
236 237 238 239 240 241 |
# File 'lib/discordrb/data/message.rb', line 236 def emoji return if @content.nil? return @emoji unless @emoji.empty? @emoji = @bot.parse_mentions(@content).select { |el| el.is_a? Discordrb::Emoji } end |
#emoji? ⇒ true, false
Check if any emoji were used in this message.
245 246 247 |
# File 'lib/discordrb/data/message.rb', line 245 def emoji? emoji&.empty? end |
#from_bot? ⇒ true, false
Returns whether this message was sent by the current Bot.
226 227 228 |
# File 'lib/discordrb/data/message.rb', line 226 def from_bot? @author&.current_bot? end |
#inspect ⇒ Object
The inspect method is overwritten to give more useful output
308 309 310 |
# File 'lib/discordrb/data/message.rb', line 308 def inspect "<Message content=\"#{@content}\" id=#{@id} timestamp=#{@timestamp} author=#{@author} channel=#{@channel}>" end |
#link ⇒ String Also known as: jump_link
Returns a URL that a user can use to navigate to this message in the client.
313 314 315 |
# File 'lib/discordrb/data/message.rb', line 313 def link "https://discord.com/channels/#{@server&.id || '@me'}/#{@channel.id}/#{@id}" end |
#my_reactions ⇒ Array<Reaction>
Returns the reactions made by the current bot or user.
257 258 259 |
# File 'lib/discordrb/data/message.rb', line 257 def my_reactions @reactions.select(&:me) end |
#pin(reason = nil) ⇒ Object
Pins this message
199 200 201 202 203 |
# File 'lib/discordrb/data/message.rb', line 199 def pin(reason = nil) API::Channel.(@bot.token, @channel.id, @id, reason) @pinned = true nil end |
#reacted_with(reaction, limit: 100) ⇒ Array<User>
Returns the list of users who reacted with a certain reaction.
277 278 279 280 281 282 283 284 285 |
# File 'lib/discordrb/data/message.rb', line 277 def reacted_with(reaction, limit: 100) reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction) paginator = Paginator.new(limit, :down) do |last_page| after_id = last_page.last.id if last_page last_page = JSON.parse(API::Channel.get_reactions(@bot.token, @channel.id, @id, reaction, nil, after_id, limit)) last_page.map { |d| User.new(d, @bot) } end paginator.to_a end |
#reactions? ⇒ true, false
Check if any reactions were used in this message.
251 252 253 |
# File 'lib/discordrb/data/message.rb', line 251 def reactions? !@reactions.empty? end |
#referenced_message ⇒ Message?
Returns the Message this Message was sent in reply to.
326 327 328 329 330 331 332 |
# File 'lib/discordrb/data/message.rb', line 326 def return @referenced_message if @referenced_message return nil unless @message_reference referenced_channel = @bot.channel(@message_reference['channel_id']) @referenced_message = referenced_channel.(@message_reference['message_id']) end |
#reply(content) ⇒ Object
Please use #respond.
Replies to this message with the specified content.
157 158 159 |
# File 'lib/discordrb/data/message.rb', line 157 def reply(content) @channel.(content) end |
#reply!(content, tts: false, embed: nil, attachments: nil, allowed_mentions: {}, mention_user: false) ⇒ Message
Sends a message to this channel.
169 170 171 172 173 174 175 |
# File 'lib/discordrb/data/message.rb', line 169 def reply!(content, tts: false, embed: nil, attachments: nil, allowed_mentions: {}, mention_user: false) allowed_mentions = { parse: [] } if allowed_mentions == false allowed_mentions = allowed_mentions.to_hash.transform_keys(&:to_sym) allowed_mentions[:replied_user] = mention_user respond(content, tts, , , allowed_mentions, self) end |
#reply? ⇒ true, false
Whether or not this message was sent in reply to another message
321 322 323 |
# File 'lib/discordrb/data/message.rb', line 321 def reply? !@referenced_message.nil? end |
#respond(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil) ⇒ Message
Sends a message to this channel.
178 179 180 |
# File 'lib/discordrb/data/message.rb', line 178 def respond(content, tts = false, = nil, = nil, allowed_mentions = nil, = nil) @channel.(content, tts, , , allowed_mentions, ) end |
#unpin(reason = nil) ⇒ Object
Unpins this message
206 207 208 209 210 |
# File 'lib/discordrb/data/message.rb', line 206 def unpin(reason = nil) API::Channel.(@bot.token, @channel.id, @id, reason) @pinned = false nil end |
#webhook? ⇒ true, false
Returns whether this message has been sent over a webhook.
231 232 233 |
# File 'lib/discordrb/data/message.rb', line 231 def webhook? !@webhook_id.nil? end |