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

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

Instance Method Summary collapse

Instance Method Details

#delete! -> Object

Note:

This will fail if the message is ephemeral.

Deletes the callback message.



239
240
241
242
243
# File 'lib/discorb/interaction.rb', line 239

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:

  • message (Discorb::Webhook::Message)

    The message to edit.

  • 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:



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/discorb/interaction.rb', line 209

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