Module: RubyCord::Interaction::UpdateResponder

Included in:
Component
Defined in:
lib/rubycord/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.



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/rubycord/interaction/response.rb', line 246

def defer_update(ephemeral: false)
  Async do
    @client
      .http
      .request(
        RubyCord::Internal::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, attachment: nil, attachments: 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 (RubyCord::Embed) (defaults to: nil)

    The embed to send.

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

    The embeds to send. (max: 10)

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

    The allowed mentions to send.

  • attachment (RubyCord::Attachment) (defaults to: nil)

    The attachment to send.

  • attachments (Array<RubyCord::Attachment>) (defaults to: nil)

    The attachments to send. (max: 10)

  • components (Array<RubyCord::Component>, Array<Array<RubyCord::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.



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/rubycord/interaction/response.rb', line 279

def edit(
  content,
  tts: false,
  embed: nil,
  embeds: nil,
  allowed_mentions: nil,
  attachment: nil,
  attachments: 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] = (
      if allowed_mentions
        allowed_mentions.to_hash(@client.allowed_mentions)
      else
        @client.allowed_mentions.to_hash
      end
    )
    payload[:components] = Component.to_payload(components) if components
    payload[:flags] = (ephemeral ? 1 << 6 : 0)
    attachments ||= [attachment] if attachment
    payload[:attachments] = attachments.map.with_index do |a, i|
      { id: i, filename: a.filename, description: a.description }
    end
    @client
      .http
      .multipart_request(
        RubyCord::Internal::Route.new(
          "/interactions/#{@id}/#{@token}/callback",
          "//interactions/:interaction_id/:token/callback",
          :post
        ),
        { type: 7, data: payload },
        attachments
      )
      .wait
  end
end