Module: Discorb::Interaction::SourceResponse
- Included in:
- CommandInteraction, MessageComponentInteraction
- Defined in:
- lib/discorb/interaction/response.rb
Overview
A module for response with source.
Defined Under Namespace
Classes: CallbackMessage
Instance Method Summary collapse
-
#defer_source(ephemeral: false) -> Object
Response with
DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
(5
). -
#post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false) -> Discorb::Interaction::SourceResponse::CallbackMessage, Discorb::Webhook::Message
Response with
CHANNEL_MESSAGE_WITH_SOURCE
(4
).
Instance Method Details
#defer_source(ephemeral: false) -> Object
Note:
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
Note:
This method calls HTTP request.
Response with DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
(5
).
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/discorb/interaction/response.rb', line 15 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) -> Discorb::Interaction::SourceResponse::CallbackMessage, Discorb::Webhook::Message
Note:
This is an asynchronous method, it will return a Async::Task
object. Use Async::Task#wait
to get the result.
Note:
This method calls HTTP request.
Response with CHANNEL_MESSAGE_WITH_SOURCE
(4
).
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/discorb/interaction/response.rb', line 43 def post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, components: nil, ephemeral: false) Async do payload = {} payload[:content] = content if content payload[:tts] = tts payload[:embeds] = ( || [])&.map { |e| e&.to_hash }.filter { _1 } payload[: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) ret = if @responded _resp, data = @client.http.post("/webhooks/#{@application_id}/#{@token}", payload).wait webhook = Webhook::URLWebhook.new("/webhooks/#{@application_id}/#{@token}") Webhook::Message.new(webhook, data, @client) elsif @defered @client.http.patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload).wait CallbackMessage.new(@client, payload, @application_id, @token) else @client.http.post("/interactions/#{@id}/#{@token}/callback", { type: 4, data: payload }).wait CallbackMessage.new(@client, payload, @application_id, @token) end @responded = true ret end end |