Class: Discordrb::Webhooks::View::ContainerBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/webhooks/view.rb

Overview

This builder can be used to construct a container. These are similar to embeds.

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, color: nil, colour: nil, spoiler: false) {|builder| ... } ⇒ ContainerBuilder

Create a container component.

Parameters:

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the container component.

  • colour (Array, Integer, String, ColourRGB, nil) (defaults to: nil)

    The accent colour of the container component. This argument can be passed via the American spelling (color:) as well.

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

    Whether or not to apply a spoiler label to the container component.

Yield Parameters:



351
352
353
354
355
356
357
358
# File 'lib/discordrb/webhooks/view.rb', line 351

def initialize(id: nil, color: nil, colour: nil, spoiler: false)
  @id = id
  @spoiler = spoiler
  @components = []
  self.colour = (colour || color)

  yield self if block_given?
end

Instance Method Details

#colour=(colour) ⇒ Object Also known as: color=

Set the color of the container.

Parameters:

  • colour (Array, Integer, String, ColourRGB, nil)

    The accent colour of the container component, or nil to clear the accent colour.



400
401
402
403
404
405
406
407
408
409
# File 'lib/discordrb/webhooks/view.rb', line 400

def colour=(colour)
  @colour = case colour
            when Array
              (colour[0] << 16) | (colour[1] << 8) | colour[2]
            when String
              colour.delete('#').to_i(16)
            else
              colour&.to_i
            end
end

#fileObject Also known as: file_display

Add a file component to the container.



368
369
370
# File 'lib/discordrb/webhooks/view.rb', line 368

def file(...)
  @components << FileBuilder.new(...)
end

Add a media gallery component to the container.



394
395
396
# File 'lib/discordrb/webhooks/view.rb', line 394

def media_gallery(...)
  @components << MediaGalleryBuilder.new(...)
end

#rowObject

Add a row component to the container.

See Also:

  • RowBuilder#initialize


362
363
364
# File 'lib/discordrb/webhooks/view.rb', line 362

def row(...)
  @components << RowBuilder.new(...)
end

#sectionObject

Add a section component to the container.



376
377
378
# File 'lib/discordrb/webhooks/view.rb', line 376

def section(...)
  @components << SectionBuilder.new(...)
end

#separatorObject

Add a separator component to the container.



382
383
384
# File 'lib/discordrb/webhooks/view.rb', line 382

def separator(...)
  @components << SeparatorBuilder.new(...)
end

#text_displayObject

Add a text display component to the container.



388
389
390
# File 'lib/discordrb/webhooks/view.rb', line 388

def text_display(...)
  @components << TextDisplayBuilder.new(...)
end