module Discorb::Interaction::SourceResponse
A module for response with source.
Public Instance Methods
defer_source(ephemeral: false)
click to toggle source
Response with `DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE`(`5`).
@param [Boolean] ephemeral Whether to make the response ephemeral.
# File lib/discorb/interaction.rb, line 104 def defer_source(ephemeral: false) Async do @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 5, data: { flags: (ephemeral ? 1 << 6 : 0), }, }).wait @defered = true end end
post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false)
click to toggle source
Response with `CHANNEL_MESSAGE_WITH_SOURCE`(`4`).
@param [String] content The content of the response. @param [Boolean] tts Whether to send the message as text-to-speech. @param [Discorb::Embed] embed The embed to send. @param [Array<Discorb::Embed>] embeds The embeds to send. (max: 10) @param [Discorb::AllowedMentions] allowed_mentions The allowed mentions to send. @param [Array<Discorb::Components>, Array<Array<Discorb::Components>>] components The components to send. @param [Boolean] ephemeral Whether to make the response ephemeral.
# File lib/discorb/interaction.rb, line 127 def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false) payload = {} payload[:content] = content if content payload[:tts] = tts tmp_embed = if embed [embed] elsif embeds embeds end payload[:embeds] = tmp_embed.map(&:to_hash) if tmp_embed payload[:allowed_mentions] = allowed_mentions ? allowed_mentions.to_hash(@client.allowed_mentions) : @client.allowed_mentions.to_hash if components tmp_components = [] tmp_row = [] components.each do |c| case c when Array tmp_components << tmp_row tmp_row = [] tmp_components << c when SelectMenu tmp_components << tmp_row tmp_row = [] tmp_components << [c] else tmp_row << c end end tmp_components << tmp_row payload[:components] = tmp_components.filter { |c| c.length.positive? }.map { |c| { type: 1, components: c.map(&:to_hash) } } end payload[:flags] = (ephemeral ? 1 << 6 : 0) if @responded @client.http.post("/webhooks/#{@id}/#{@token}", { type: 4, data: payload }).wait elsif @defered @client.http.post("/interactions/#{@id}/#{@token}/@original/edit", { type: 4, data: payload }).wait else @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 4, data: payload }).wait end @responded = true end