Class: Discorb::Interaction::SourceResponse::CallbackMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/discorb/interaction/response.rb

Instance Method Summary collapse

Instance Method Details

#delete! -> Object

Note:

This will fail if the message is ephemeral.

Deletes the callback message.



121
122
123
124
125
# File 'lib/discorb/interaction/response.rb', line 121

def delete!
  Async do
    @client.http.delete("/webhooks/#{@application_id}/#{@token}/messages/@original").wait
  end
end

#edit(content = :unset, embed: :unset, embeds: :unset, file: :unset, files: :unset, attachments: :unset) -> Object Also known as: modify

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.

Note:

The arguments of this method are defaultly set to :unset. Specify value to set the value, if not don't specify or specify :unset.

Edits the callback message.

Parameters:

  • content (String) (defaults to: :unset)

    The new content of the message.

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

    The new embed of the message.

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

    The new embeds of the message.

  • attachments (Array<Discorb::Attachment>) (defaults to: :unset)

    The attachments to remain.

  • file (Discorb::File) (defaults to: :unset)

    The file to send.

  • files (Array<Discorb::File>) (defaults to: :unset)

    The files to send.

Raises:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/discorb/interaction/response.rb', line 91

def edit(
  content = :unset,
  embed: :unset, embeds: :unset,
  file: :unset, files: :unset,
  attachments: :unset
)
  Async do
    payload = {}
    payload[:content] = content if content != :unset
    payload[:embeds] = embed ? [embed.to_hash] : [] if embed != :unset
    payload[:embeds] = embeds.map(&:to_hash) if embeds != :unset
    payload[:attachments] = attachments.map(&:to_hash) if attachments != :unset
    files = [file] if file != :unset
    if files == :unset
      headers = {
        "Content-Type" => "application/json",
      }
    else
      headers, payload = HTTP.multipart(payload, files)
    end
    @client.http.patch("/webhooks/#{@application_id}/#{@token}/messages/@original", payload, headers: headers).wait
  end
end