Module: Discorb::Interaction::UpdateResponder

Included in:
MessageComponentInteraction
Defined in:
lib/discorb/interaction/response.rb

Overview

A module for response with update.

Instance Method Summary collapse

Instance Method Details

#defer_update(ephemeral: false) -> Async::Task<void>

Response with DEFERRED_UPDATE_MESSAGE(6).

Parameters:

  • ephemeral (Boolean) (defaults to: false)

    Whether to make the response ephemeral.

Returns:

  • (Async::Task<void>)

    The task.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/discorb/interaction/response.rb', line 187

def defer_update(ephemeral: false)
  Async do
    @client.http.request(
      Route.new(
        "/interactions/#{@id}/#{@token}/callback",
        "//interactions/:interaction_id/:token/callback",
        :post
      ), {
        type: 6,
        data: {
          flags: (ephemeral ? 1 << 6 : 0),
        },
      }
    ).wait
  end
end

#edit(content, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false) -> Async::Task<void>

Response with UPDATE_MESSAGE(7).

Parameters:

  • content (String)

    The content of the response.

  • tts (Boolean) (defaults to: false)

    Whether to send the message as text-to-speech.

  • embed (Discorb::Embed) (defaults to: nil)

    The embed to send.

  • embeds (Array<Discorb::Embed>) (defaults to: nil)

    The embeds to send. (max: 10)

  • allowed_mentions (Discorb::AllowedMentions) (defaults to: nil)

    The allowed mentions to send.

  • components (Array<Discorb::Component>, Array<Array<Discorb::Component>>) (defaults to: nil)

    The components to send.

  • ephemeral (Boolean) (defaults to: false)

    Whether to make the response ephemeral.

Returns:

  • (Async::Task<void>)

    The task.



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/discorb/interaction/response.rb', line 219

def edit(content, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false)
  Async do
    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
    payload[:components] = Component.to_payload(components) if components
    payload[:flags] = (ephemeral ? 1 << 6 : 0)
    @client.http.request(
      Route.new("/interactions/#{@id}/#{@token}/callback", "//interactions/:interaction_id/:token/callback",
                :post), { type: 7, data: payload }
    ).wait
  end
end