Module: Discordrb::API::Interaction

Defined in:
lib/discordrb/api/interaction.rb

Overview

API calls for interactions.

Class Method Summary collapse

Class Method Details

.create_interaction_modal_response(interaction_token, interaction_id, custom_id, title, components) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/discordrb/api/interaction.rb', line 33

def create_interaction_modal_response(interaction_token, interaction_id, custom_id, title, components)
  data = { custom_id: custom_id, title: title, components: components.to_a }.compact

  Discordrb::API.request(
    :interactions_iid_token_callback,
    interaction_id,
    :post,
    "#{Discordrb::API.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
    { type: 9, data: data }.to_json,
    content_type: :json
  )
end

.create_interaction_response(interaction_token, interaction_id, type, content = nil, tts = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/discordrb/api/interaction.rb', line 9

def create_interaction_response(interaction_token, interaction_id, type, content = nil, tts = nil, embeds = nil, allowed_mentions = nil, flags = nil, components = nil, attachments = nil)
  body = { tts: tts, content: content, embeds: embeds, allowed_mentions: allowed_mentions, flags: flags, components: components }.compact

  body = if attachments
           files = [*0...attachments.size].zip(attachments).to_h
           { **files, payload_json: { type: type, data: body }.to_json }
         else
           { type: type, data: body }.to_json
         end

  headers = { content_type: :json } unless attachments

  Discordrb::API.request(
    :interactions_iid_token_callback,
    interaction_id,
    :post,
    "#{Discordrb::API.api_base}/interactions/#{interaction_id}/#{interaction_token}/callback",
    body,
    headers
  )
end

.delete_original_interaction_response(interaction_token, application_id) ⇒ Object



60
61
62
# File 'lib/discordrb/api/interaction.rb', line 60

def delete_original_interaction_response(interaction_token, application_id)
  Discordrb::API::Webhook.token_delete_message(interaction_token, application_id, '@original')
end

.edit_original_interaction_response(interaction_token, application_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil) ⇒ Object



54
55
56
# File 'lib/discordrb/api/interaction.rb', line 54

def edit_original_interaction_response(interaction_token, application_id, content = nil, embeds = nil, allowed_mentions = nil, components = nil, attachments = nil)
  Discordrb::API::Webhook.token_edit_message(interaction_token, application_id, '@original', content, embeds, allowed_mentions, components, attachments)
end

.get_original_interaction_response(interaction_token, application_id) ⇒ Object



48
49
50
# File 'lib/discordrb/api/interaction.rb', line 48

def get_original_interaction_response(interaction_token, application_id)
  Discordrb::API::Webhook.token_get_message(interaction_token, application_id, '@original')
end