class Discordrb::Interactions::Message

A message partial for interactions.

Attributes

attachments[R]

@return [Attachment]

author[R]

@return [User] The user of the application.

channel_id[R]

@return [Integer]

components[R]

@return [Array<Component>]

content[R]

@return [String, nil] The content of the message.

edited[R]

@return [true, false]

edited_timestamp[R]

@return [Time, nil]

embeds[R]

@return [Array<Embed>]

flags[R]

@return [Integer]

id[R]

@return [Integer]

interaction[R]

@return [Interaction] The interaction that created this message.

mentions[R]

@return [Array<User>]

message_reference[R]

@return [Hash, nil]

pinned[R]

@return [true, false] Whether this message is pinned in the channel it belongs to.

timestamp[R]

@return [Time]

tts[R]

@return [true, false]

Public Class Methods

new(data, bot, interaction) click to toggle source

@!visibility private

# File lib/discordrb/data/interaction.rb, line 708
def initialize(data, bot, interaction)
  @data = data
  @bot = bot
  @interaction = interaction
  @content = data['content']
  @channel_id = data['channel_id'].to_i
  @pinned = data['pinned']
  @tts = data['tts']

  @message_reference = data['message_reference']

  @server_id = data['guild_id']&.to_i

  @timestamp = Time.parse(data['timestamp']) if data['timestamp']
  @edited_timestamp = data['edited_timestamp'].nil? ? nil : Time.parse(data['edited_timestamp'])
  @edited = !@edited_timestamp.nil?

  @id = data['id'].to_i

  @author = bot.ensure_user(data['author'] || data['member']['user'])

  @attachments = []
  @attachments = data['attachments'].map { |e| Attachment.new(e, self, @bot) } if data['attachments']

  @embeds = []
  @embeds = data['embeds'].map { |e| Embed.new(e, self) } if data['embeds']

  @mentions = []

  data['mentions']&.each do |element|
    @mentions << bot.ensure_user(element)
  end

  @mention_roles = data['mention_roles']
  @mention_everyone = data['mention_everyone']
  @flags = data['flags']
  @pinned = data['pinned']
  @components = data['components'].map { |component_data| Components.from_data(component_data, @bot) } if data['components']
end

Public Instance Methods

channel() click to toggle source

@return [Channel] The channel the interaction originates from. @raise [Errors::NoPermission] When the bot is not in the server associated with this interaction.

# File lib/discordrb/data/interaction.rb, line 762
def channel
  @bot.channel(@channel_id)
end
delete() click to toggle source

Delete this message.

# File lib/discordrb/data/interaction.rb, line 774
def delete
  @interaction.delete_message(@id)
end
edit(content: nil, embeds: nil, allowed_mentions: nil, components: nil, &block) click to toggle source

Edit this message’s data. @param content (see Interaction#send_message) @param embeds (see Interaction#send_message) @param allowed_mentions (see Interaction#send_message) @yieldparam (see Interaction#send_message)

# File lib/discordrb/data/interaction.rb, line 783
def edit(content: nil, embeds: nil, allowed_mentions: nil, components: nil, &block)
  @interaction.edit_message(@id, content: content, embeds: embeds, allowed_mentions: allowed_mentions, components: components, &block)
end
inspect() click to toggle source

@!visibility private

# File lib/discordrb/data/interaction.rb, line 795
def inspect
  "<Interaction::Message content=#{@content.inspect} embeds=#{@embeds.inspect} channel_id=#{@channel_id} server_id=#{@server_id} author=#{@author.inspect}>"
end
member() click to toggle source

@return [Member, nil] This will return nil if the bot does not have access to the

server the interaction originated in.
# File lib/discordrb/data/interaction.rb, line 750
def member
  server&.member(@user.id)
end
message()
Alias for: to_message
respond(content: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: true, components: nil, &block) click to toggle source

Respond to this message. @param (see Interaction#send_message) @yieldparam (see Interaction#send_message)

# File lib/discordrb/data/interaction.rb, line 769
def respond(content: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: true, components: nil, &block)
  @interaction.send_message(content: content, embeds: embeds, allowed_mentions: allowed_mentions, flags: flags, ephemeral: ephemeral, components: components, &block)
end
server() click to toggle source

@return [Server, nil] This will return nil if the bot does not have access to the

server the interaction originated in.
# File lib/discordrb/data/interaction.rb, line 756
def server
  @bot.server(@server_id)
end
to_message() click to toggle source

@return [Discordrb::Message]

# File lib/discordrb/data/interaction.rb, line 788
def to_message
  Discordrb::Message.new(@data, @bot)
end
Also aliased as: message