Class: Discordrb::Message

Inherits:
Object
  • Object
show all
Includes:
IDObject
Defined in:
lib/discordrb/data/message.rb

Overview

A message on Discord that was sent to a text channel

Constant Summary collapse

FLAGS =

Map of message flags.

{
  crossposted: 1 << 0,
  crosspost: 1 << 1,
  suppress_embeds: 1 << 2,
  source_message_deleted: 1 << 3,
  urgent: 1 << 4,
  thread: 1 << 5,
  ephemeral: 1 << 6,
  loading: 1 << 7,
  failed_to_mention_roles: 1 << 8,
  suppress_notifications: 1 << 12,
  voice_message: 1 << 13,
  snapshot: 1 << 14,
  uikit_components: 1 << 15
}.freeze
TYPES =

Map of message types.

{
  default: 0,
  recipient_add: 1,
  recipient_remove: 2,
  call: 3,
  channel_name_change: 4,
  channel_icon_change: 5,
  channel_pinned_message: 6,
  server_member_join: 7,
  server_boost: 8,
  server_boost_tier_one: 9,
  server_boost_tier_two: 10,
  server_boost_tier_three: 11,
  channel_follow_add: 12,
  server_discovery_disqualified: 14,
  server_discovery_requalified: 15,
  server_discovery_grace_period_initial_warning: 16,
  server_discovery_grace_period_final_warning: 17,
  thread_created: 18,
  reply: 19,
  chat_input_command: 20,
  thread_starter_message: 21,
  server_invite_reminder: 22,
  context_menu_command: 23,
  automod_action: 24,
  role_subscription_purchase: 25,
  interaction_premium_upsell: 26,
  stage_start: 27,
  stage_end: 28,
  stage_speaker: 29,
  stage_raise_hand: 30,
  stage_topic: 31,
  server_application_premium_subscription: 32,
  server_incident_alert_mode_enabled: 36,
  server_incident_alert_mode_disabled: 37,
  server_incident_report_raid: 38,
  server_incident_report_false_alarm: 39,
  purchase_notification: 44,
  poll_result: 46,
  changelog: 47,
  server_join_request_accepted: 52,
  server_join_request_rejected: 53,
  server_join_request_withdrawn: 54,
  report_to_mod_deleted_message: 58,
  report_to_mod_timeout_user: 59,
  report_to_mod_kick_user: 60,
  report_to_mod_ban_user: 61,
  report_to_mod_closed_report: 62,
  server_emoji_added: 63
}.freeze

Instance Attribute Summary collapse

Attributes included from IDObject

#id

Instance Method Summary collapse

Methods included from IDObject

#==, #creation_time, synthesise

Instance Attribute Details

#attachmentsArray<Attachment> (readonly)

Returns the files attached to this message.

Returns:

  • (Array<Attachment>)

    the files attached to this message.



99
100
101
# File 'lib/discordrb/data/message.rb', line 99

def attachments
  @attachments
end

#callCall? (readonly)

Returns the call in a private channel that prompted this message.

Returns:

  • (Call, nil)

    the call in a private channel that prompted this message.



149
150
151
# File 'lib/discordrb/data/message.rb', line 149

def call
  @call
end

#channelChannel (readonly)

Returns the channel in which this message was sent.

Returns:

  • (Channel)

    the channel in which this message was sent.



83
84
85
# File 'lib/discordrb/data/message.rb', line 83

def channel
  @channel
end

#componentsArray<Component> (readonly)

Returns Interaction components for this message.

Returns:

  • (Array<Component>)

    Interaction components for this message.



137
138
139
# File 'lib/discordrb/data/message.rb', line 137

def components
  @components
end

#contentString (readonly) Also known as: text, to_s

Returns the content of this message.

Returns:

  • (String)

    the content of this message.



78
79
80
# File 'lib/discordrb/data/message.rb', line 78

def content
  @content
end

#editedtrue, false (readonly) Also known as: edited?

Returns whether the message was edited or not.

Returns:

  • (true, false)

    whether the message was edited or not.



115
116
117
# File 'lib/discordrb/data/message.rb', line 115

def edited
  @edited
end

#edited_timestampTime (readonly) Also known as: edit_timestamp

Returns the timestamp at which this message was edited. nil if the message was never edited.

Returns:

  • (Time)

    the timestamp at which this message was edited. nil if the message was never edited.



89
90
91
# File 'lib/discordrb/data/message.rb', line 89

def edited_timestamp
  @edited_timestamp
end

#embedsArray<Embed> (readonly)

Returns the embed objects contained in this message.

Returns:

  • (Array<Embed>)

    the embed objects contained in this message.



102
103
104
# File 'lib/discordrb/data/message.rb', line 102

def embeds
  @embeds
end

#flagsInteger (readonly)

Returns flags set on the message.

Returns:

  • (Integer)

    flags set on the message.



140
141
142
# File 'lib/discordrb/data/message.rb', line 140

def flags
  @flags
end

#mention_everyonetrue, false (readonly) Also known as: mention_everyone?, mentions_everyone?

Returns whether the message mentioned everyone or not.

Returns:

  • (true, false)

    whether the message mentioned everyone or not.



119
120
121
# File 'lib/discordrb/data/message.rb', line 119

def mention_everyone
  @mention_everyone
end

#mentionsArray<User> (readonly)

Returns the users that were mentioned in this message.

Returns:

  • (Array<User>)

    the users that were mentioned in this message.



93
94
95
# File 'lib/discordrb/data/message.rb', line 93

def mentions
  @mentions
end

#nonceString (readonly)

Returns used for validating a message was sent.

Returns:

  • (String)

    used for validating a message was sent.



112
113
114
# File 'lib/discordrb/data/message.rb', line 112

def nonce
  @nonce
end

#pinnedtrue, false (readonly) Also known as: pinned?

Returns whether the message is pinned or not.

Returns:

  • (true, false)

    whether the message is pinned or not.



124
125
126
# File 'lib/discordrb/data/message.rb', line 124

def pinned
  @pinned
end

#pinned_atTime? (readonly)

Returns the time at when this message was pinned. Only present on messages fetched via Channel#pins.

Returns:

  • (Time, nil)

    the time at when this message was pinned. Only present on messages fetched via Channel#pins.



146
147
148
# File 'lib/discordrb/data/message.rb', line 146

def pinned_at
  @pinned_at
end

#reactionsArray<Reaction> (readonly)

Returns the reaction objects contained in this message.

Returns:

  • (Array<Reaction>)

    the reaction objects contained in this message.



105
106
107
# File 'lib/discordrb/data/message.rb', line 105

def reactions
  @reactions
end

#role_mentionsArray<Role> (readonly)

Returns the roles that were mentioned in this message.

Returns:

  • (Array<Role>)

    the roles that were mentioned in this message.



96
97
98
# File 'lib/discordrb/data/message.rb', line 96

def role_mentions
  @role_mentions
end

#serverServer? (readonly)

Returns the server in which this message was sent.

Returns:

  • (Server, nil)

    the server in which this message was sent.



131
132
133
# File 'lib/discordrb/data/message.rb', line 131

def server
  @server
end

#snapshotsArray<Snapshot> (readonly)

Returns the message snapshots included in this message.

Returns:

  • (Array<Snapshot>)

    the message snapshots included in this message.



152
153
154
# File 'lib/discordrb/data/message.rb', line 152

def snapshots
  @snapshots
end

#threadChannel? (readonly)

Returns The thread that was started from this message, or nil.

Returns:

  • (Channel, nil)

    The thread that was started from this message, or nil.



143
144
145
# File 'lib/discordrb/data/message.rb', line 143

def thread
  @thread
end

#timestampTime (readonly)

Returns the timestamp at which this message was sent.

Returns:

  • (Time)

    the timestamp at which this message was sent.



86
87
88
# File 'lib/discordrb/data/message.rb', line 86

def timestamp
  @timestamp
end

#ttstrue, false (readonly) Also known as: tts?

Returns whether the message used Text-To-Speech (TTS) or not.

Returns:

  • (true, false)

    whether the message used Text-To-Speech (TTS) or not.



108
109
110
# File 'lib/discordrb/data/message.rb', line 108

def tts
  @tts
end

#typeInteger (readonly)

Returns what the type of the message is.

Returns:

  • (Integer)

    what the type of the message is



128
129
130
# File 'lib/discordrb/data/message.rb', line 128

def type
  @type
end

#webhook_idInteger? (readonly)

Returns the webhook ID that sent this message, or nil if it wasn't sent through a webhook.

Returns:

  • (Integer, nil)

    the webhook ID that sent this message, or nil if it wasn't sent through a webhook.



134
135
136
# File 'lib/discordrb/data/message.rb', line 134

def webhook_id
  @webhook_id
end

Instance Method Details

#all_reaction_users(limit: 100) ⇒ Hash<String => Array<User>>

Returns a hash of all reactions to a message as keys and the users that reacted to it as values.

Examples:

Get all the users that reacted to a message for a giveaway.

giveaway_participants = message.all_reaction_users

Parameters:

  • limit (Integer) (defaults to: 100)

    the limit of how many users to retrieve per distinct reaction emoji. nil will return all users

Returns:

  • (Hash<String => Array<User>>)

    A hash mapping the string representation of a reaction to an array of users.



451
452
453
454
# File 'lib/discordrb/data/message.rb', line 451

def all_reaction_users(limit: 100)
  all_reactions = @reactions.map { |r| { r.to_s => reacted_with(r, limit: limit) } }
  all_reactions.reduce({}, :merge)
end

#authorMember, User 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).

Returns:

  • (Member, User)

    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)



238
239
240
241
242
243
244
245
246
247
# File 'lib/discordrb/data/message.rb', line 238

def author
  return @author if @author

  if @channel.server
    @author = @channel.server.member(@author_id)
    Discordrb::LOGGER.debug("Member with ID #{@author_id} not cached (possibly left the server).") if @author.nil?
  end

  @author ||= @bot.user(@author_id)
end

#await(key, attributes = {}, &block) ⇒ Object

Deprecated.

Will be changed to blocking behavior in v4.0. Use #await! instead.

Add an Await for a message with the same user and channel.

See Also:



328
329
330
# File 'lib/discordrb/data/message.rb', line 328

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.

See Also:



334
335
336
# File 'lib/discordrb/data/message.rb', line 334

def await!(attributes = {}, &block)
  @bot.add_await!(Discordrb::Events::MessageEvent, { from: @author.id, in: @channel.id }.merge(attributes), &block)
end

#await_reaction(key, attributes = {}, &block) ⇒ Object

Deprecated.

Will be changed to blocking behavior in v4.0. Use #await_reaction! instead.

Add an Await for a reaction to be added on this message.

See Also:



341
342
343
# File 'lib/discordrb/data/message.rb', line 341

def await_reaction(key, attributes = {}, &block)
  @bot.add_await(key, Discordrb::Events::ReactionAddEvent, { message: @id }.merge(attributes), &block)
end

#await_reaction!(attributes = {}, &block) ⇒ Object

Add a blocking Await for a reaction to be added on this message.

See Also:



347
348
349
# File 'lib/discordrb/data/message.rb', line 347

def await_reaction!(attributes = {}, &block)
  @bot.add_await!(Discordrb::Events::ReactionAddEvent, { message: @id }.merge(attributes), &block)
end

#buttonsArray<Components::Button>

Returns:



504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/discordrb/data/message.rb', line 504

def buttons
  results = @components.collect do |component|
    case component
    when Components::Button
      component
    when Components::ActionRow
      component.buttons
    end
  end

  results.flatten.compact
end

#create_reaction(reaction) ⇒ Object Also known as: react

Reacts to a message.

Parameters:

  • reaction (String, #to_reaction)

    the unicode emoji or Emoji



408
409
410
411
412
# File 'lib/discordrb/data/message.rb', line 408

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

#crosspostObject

Crossposts a message in a news channel.



320
321
322
323
# File 'lib/discordrb/data/message.rb', line 320

def crosspost
  response = API::Channel.crosspost_message(@bot.token, @channel.id, @id)
  Message.new(JSON.parse(response), @bot)
end

#delete(reason = nil) ⇒ Object

Deletes this message.



300
301
302
303
# File 'lib/discordrb/data/message.rb', line 300

def delete(reason = nil)
  API::Channel.delete_message(@bot.token, @channel.id, @id, reason)
  nil
end

#delete_all_reactionsObject

Removes all reactions from this message.



472
473
474
# File 'lib/discordrb/data/message.rb', line 472

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.

Parameters:

  • reaction (String, #to_reaction)

    the reaction to remove



466
467
468
469
# File 'lib/discordrb/data/message.rb', line 466

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.

Parameters:

  • user (User, String, Integer)

    the user or user ID who used this reaction

  • reaction (String, #to_reaction)

    the reaction to remove



459
460
461
462
# File 'lib/discordrb/data/message.rb', line 459

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_embeds = nil, new_components = nil, flags = 0) ⇒ Message

Edits this message to have the specified content instead. You can only edit your own messages.

Parameters:

  • new_content (String)

    the new content the message should have.

  • new_embeds (Hash, Discordrb::Webhooks::Embed, Array<Hash>, Array<Discordrb::Webhooks::Embed>, nil) (defaults to: nil)

    The new embeds the message should have. If nil the message will be changed to have no embeds.

  • new_components (View, Array<Hash>) (defaults to: nil)

    The new components the message should have. If nil the message will be changed to have no components.

  • flags (Integer) (defaults to: 0)

    Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) can be edited.

Returns:

  • (Message)

    the resulting message.



291
292
293
294
295
296
297
# File 'lib/discordrb/data/message.rb', line 291

def edit(new_content, new_embeds = nil, new_components = nil, flags = 0)
  new_embeds = (new_embeds.instance_of?(Array) ? new_embeds.map(&:to_hash) : [new_embeds&.to_hash]).compact
  new_components = new_components.to_a

  response = API::Channel.edit_message(@bot.token, @channel.id, @id, new_content, [], new_embeds, new_components, flags)
  Message.new(JSON.parse(response), @bot)
end

#emojiArray<Emoji>

Returns the emotes that were used/mentioned in this message.

Returns:

  • (Array<Emoji>)

    the emotes that were used/mentioned in this message.



362
363
364
365
366
367
# File 'lib/discordrb/data/message.rb', line 362

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.

Returns:

  • (true, false)

    whether or not any emoji were used



371
372
373
# File 'lib/discordrb/data/message.rb', line 371

def emoji?
  emoji&.empty?
end

#forward(channel, must_exist: true, timeout: nil, flags: 0, nonce: nil, enforce_nonce: false) ⇒ Message?

Forward this message to another channel.

Parameters:

  • channel (Integer, String, Channel)

    The target channel to forward this message to.

  • must_exist (true, false) (defaults to: true)

    Whether to raise an error if this message was deleted when sending it.

  • timeout (Float, nil) (defaults to: nil)

    The amount of time in seconds after which the message sent will be deleted.

  • flags (Integer, Symbol, Array<Integer, Symbol>) (defaults to: 0)

    The message flags to set on the forwarded message.

  • nonce (String, Integer, nil) (defaults to: nil)

    The 25 character optional nonce that should be used when forwarding this message.

  • enforce_nonce (true, false) (defaults to: false)

    Whether the provided nonce should be enforced and used for message de-duplication.

Returns:

  • (Message, nil)

    the message that was created from forwarding this one, or nil if this is a temporary message.



555
556
557
558
559
# File 'lib/discordrb/data/message.rb', line 555

def forward(channel, must_exist: true, timeout: nil, flags: 0, nonce: nil, enforce_nonce: false)
  reference = to_reference(type: :forward, must_exist: must_exist)

  @bot.channel(channel).send_message!(reference: reference, timeout: timeout, flags: flags, nonce: nonce, enforce_nonce: enforce_nonce)
end

#from_bot?true, false

Returns whether this message was sent by the current Bot.

Returns:

  • (true, false)

    whether this message was sent by the current Bot.



352
353
354
# File 'lib/discordrb/data/message.rb', line 352

def from_bot?
  @author&.current_bot?
end

#inspectObject

The inspect method is overwritten to give more useful output



477
478
479
# File 'lib/discordrb/data/message.rb', line 477

def inspect
  "<Message content=\"#{@content}\" id=#{@id} timestamp=#{@timestamp} author=#{@author} channel=#{@channel}>"
end

Returns a URL that a user can use to navigate to this message in the client.

Returns:

  • (String)

    a URL that a user can use to navigate to this message in the client



482
483
484
# File 'lib/discordrb/data/message.rb', line 482

def link
  "https://discord.com/channels/#{@server&.id || '@me'}/#{@channel.id}/#{@id}"
end

#mentions?(target) ⇒ true, false

Check if this message mentions a specific user or role.

Parameters:

Returns:

  • (true, false)

    whether or not this message mentions the target.



398
399
400
401
402
403
404
# File 'lib/discordrb/data/message.rb', line 398

def mentions?(target)
  mentions = (@mentions + role_mentions)

  mentions << server if @mention_everyone

  mentions.any?(target.resolve_id)
end

#my_reactionsArray<Reaction>

Returns the reactions made by the current bot or user.

Returns:



383
384
385
# File 'lib/discordrb/data/message.rb', line 383

def my_reactions
  @reactions.select(&:me)
end

#pin(reason = nil) ⇒ Object

Pins this message



306
307
308
309
310
# File 'lib/discordrb/data/message.rb', line 306

def pin(reason = nil)
  API::Channel.pin_message(@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.

Examples:

Get all the users that reacted with a thumbs up.

thumbs_up_reactions = message.reacted_with("\u{1F44D}")

Parameters:

  • reaction (String, #to_reaction)

    the unicode emoji or Emoji

  • limit (Integer) (defaults to: 100)

    the limit of how many users to retrieve. nil will return all users

Returns:

  • (Array<User>)

    the users who used this reaction



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
# File 'lib/discordrb/data/message.rb', line 422

def reacted_with(reaction, limit: 100)
  reaction = reaction.to_reaction if reaction.respond_to?(:to_reaction)
  reaction = reaction.to_s if reaction.respond_to?(:to_s)

  get_reactions = proc do |fetch_limit, after_id = nil|
    resp = API::Channel.get_reactions(@bot.token, @channel.id, @id, reaction, nil, after_id, fetch_limit)
    JSON.parse(resp).map { |d| User.new(d, @bot) }
  end

  # Can be done without pagination
  return get_reactions.call(limit) if limit && limit <= 100

  paginator = Paginator.new(limit, :down) do |last_page|
    if last_page && last_page.count < 100
      []
    else
      get_reactions.call(100, last_page&.last&.id)
    end
  end

  paginator.to_a
end

#reactions?true, false

Check if any reactions were used in this message.

Returns:

  • (true, false)

    whether or not this message has reactions



377
378
379
# File 'lib/discordrb/data/message.rb', line 377

def reactions?
  !@reactions.empty?
end

#referenced_messageMessage?

Returns the Message this Message was sent in reply to.

Returns:

  • (Message, nil)

    the Message this Message was sent in reply to.



495
496
497
498
499
500
501
# File 'lib/discordrb/data/message.rb', line 495

def referenced_message
  return @referenced_message if @referenced_message
  return nil unless @message_reference

  referenced_channel = @bot.channel(@message_reference['channel_id'])
  @referenced_message = referenced_channel&.message(@message_reference['message_id'])
end

#reply(content) ⇒ Message

Deprecated.

Please use #respond.

Replies to this message with the specified content.

Parameters:

  • content (String)

    The content to send. Should not be longer than 2000 characters or it will result in an error.

Returns:

  • (Message)

    the message that was sent.

See Also:



257
258
259
# File 'lib/discordrb/data/message.rb', line 257

def reply(content)
  @channel.send_message(content)
end

#reply!(content, tts: false, embed: nil, attachments: nil, allowed_mentions: {}, mention_user: false, components: nil, flags: 0) ⇒ Message

Responds to this message as an inline reply.

Parameters:

  • content (String)

    The content to send. Should not be longer than 2000 characters or it will result in an error.

  • tts (true, false) (defaults to: false)

    Whether or not this message should be sent using Discord text-to-speech.

  • embed (Hash, Discordrb::Webhooks::Embed, nil) (defaults to: nil)

    The rich embed to append to this message.

  • attachments (Array<File>) (defaults to: nil)

    Files that can be referenced in embeds via attachment://file.png

  • allowed_mentions (Hash, Discordrb::AllowedMentions, false, nil) (defaults to: {})

    Mentions that are allowed to ping on this message. false disables all pings

  • mention_user (true, false) (defaults to: false)

    Whether the user that is being replied to should be pinged by the reply.

  • components (View, Array<Hash>) (defaults to: nil)

    Interaction components to associate with this message.

  • flags (Integer) (defaults to: 0)

    Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) and SUPPRESS_NOTIFICATIONS (1 << 12) can be set.

Returns:

  • (Message)

    the message that was sent.



271
272
273
274
275
276
277
# File 'lib/discordrb/data/message.rb', line 271

def reply!(content, tts: false, embed: nil, attachments: nil, allowed_mentions: {}, mention_user: false, components: nil, flags: 0)
  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, embed, attachments, allowed_mentions, self, components, flags)
end

#reply?true, false

Whether or not this message was sent in reply to another message

Returns:

  • (true, false)


490
491
492
# File 'lib/discordrb/data/message.rb', line 490

def reply?
  !@referenced_message.nil?
end

#respond(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0) ⇒ Message

Sends a message to this channel.

Parameters:

  • content (String)

    The content to send. Should not be longer than 2000 characters or it will result in an error.

  • tts (true, false) (defaults to: false)

    Whether or not this message should be sent using Discord text-to-speech.

  • embed (Hash, Discordrb::Webhooks::Embed, nil) (defaults to: nil)

    The rich embed to append to this message.

  • attachments (Array<File>) (defaults to: nil)

    Files that can be referenced in embeds via attachment://file.png

  • allowed_mentions (Hash, Discordrb::AllowedMentions, false, nil) (defaults to: nil)

    Mentions that are allowed to ping on this message. false disables all pings

  • message_reference (Message, String, Integer, nil) (defaults to: nil)

    The message, or message ID, to reply to if any.

  • components (View, Array<Hash>) (defaults to: nil)

    Interaction components to associate with this message.

  • flags (Integer) (defaults to: 0)

    Flags for this message. Currently only SUPPRESS_EMBEDS (1 << 2) and SUPPRESS_NOTIFICATIONS (1 << 12) can be set.

Returns:

  • (Message)

    the message that was sent.



280
281
282
# File 'lib/discordrb/data/message.rb', line 280

def respond(content, tts = false, embed = nil, attachments = nil, allowed_mentions = nil, message_reference = nil, components = nil, flags = 0)
  @channel.send_message(content, tts, embed, attachments, allowed_mentions, message_reference, components, flags)
end

#suppress_embedsMessage

Removes embeds from the message

Returns:

  • (Message)

    the resulting message.



389
390
391
392
393
# File 'lib/discordrb/data/message.rb', line 389

def suppress_embeds
  flags = @flags | (1 << 2)
  response = API::Channel.edit_message(@bot.token, @channel.id, @id, :undef, :undef, :undef, :undef, flags)
  Message.new(JSON.parse(response), @bot)
end

#to_messageDiscordrb::Message Also known as: message

to_message -> self or message

Returns:



519
520
521
# File 'lib/discordrb/data/message.rb', line 519

def to_message
  self
end

#to_reference(type: :reply, must_exist: true) ⇒ Hash

Convert this message to a hash that can be used to reference this message in a forward or a reply.

Parameters:

  • type (Integer, Symbol) (defaults to: :reply)

    The reference type to set. Can either be one of :reply or :forward.

  • must_exist (true, false) (defaults to: true)

    Whether to raise an error if this message was deleted when sending it.

Returns:

  • (Hash)

    the message as a hash representation that can be used in a forwarded message or a reply.



541
542
543
544
545
# File 'lib/discordrb/data/message.rb', line 541

def to_reference(type: :reply, must_exist: true)
  type = (type == :reply ? 0 : 1) if type.is_a?(Symbol)

  { type: type, message_id: @id, channel_id: @channel.id, fail_if_not_exists: must_exist }
end

#unpin(reason = nil) ⇒ Object

Unpins this message



313
314
315
316
317
# File 'lib/discordrb/data/message.rb', line 313

def unpin(reason = nil)
  API::Channel.unpin_message(@bot.token, @channel.id, @id, reason)
  @pinned = false
  nil
end

#webhook?true, false

Returns whether this message has been sent over a webhook.

Returns:

  • (true, false)

    whether this message has been sent over a webhook.



357
358
359
# File 'lib/discordrb/data/message.rb', line 357

def webhook?
  !@webhook_id.nil?
end