Method: Discordrb::Webhooks::Client#execute

Defined in:
lib/discordrb/webhooks/client.rb

#execute(builder = nil, wait = false, components = nil, thread_id: nil) {|builder| ... } ⇒ RestClient::Response

Executes the webhook this client points to with the given data.

Examples:

Execute the webhook with an already existing builder

builder = Discordrb::Webhooks::Builder.new # ...
client.execute(builder)

Execute the webhook by building a new message

client.execute do |builder|
  builder.content = 'Testing'
  builder.username = 'discordrb'
  builder.add_embed do |embed|
    embed.timestamp = Time.now
    embed.title = 'Testing'
    embed.image = Discordrb::Webhooks::EmbedImage.new(url: 'https://i.imgur.com/PcMltU7.jpg')
  end
end

Parameters:

  • builder (Builder, nil) (defaults to: nil)

    The builder to start out with, or nil if one should be created anew.

  • wait (true, false) (defaults to: false)

    Whether Discord should wait for the message to be successfully received by clients, or whether it should return immediately after sending the message.

  • thread_id (String, Integer, nil) (defaults to: nil)

    The thread_id of the thread if a thread should be targeted for the webhook execution

Yields:

  • (builder)

    Gives the builder to the block to add additional steps, or to do the entire building process.

Yield Parameters:

  • builder (Builder)

    The builder given as a parameter which is used as the initial step to start from.

Returns:

  • (RestClient::Response)

    the response returned by Discord.

Raises:

  • (TypeError)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/discordrb/webhooks/client.rb', line 42

def execute(builder = nil, wait = false, components = nil, thread_id: nil)
  raise TypeError, 'builder needs to be nil or like a Discordrb::Webhooks::Builder!' unless
    (builder.respond_to?(:file) && builder.respond_to?(:to_multipart_hash)) || builder.respond_to?(:to_json_hash) || builder.nil?

  builder ||= Builder.new
  view = View.new

  yield(builder, view) if block_given?

  components ||= view

  if builder.file
    post_multipart(builder, components, wait, thread_id)
  else
    post_json(builder, components, wait, thread_id)
  end
end