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:



379
380
381
382
383
384
385
386
# File 'lib/discordrb/webhooks/view.rb', line 379

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.



428
429
430
431
432
433
434
435
436
437
# File 'lib/discordrb/webhooks/view.rb', line 428

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.



396
397
398
# File 'lib/discordrb/webhooks/view.rb', line 396

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

Add a media gallery component to the container.



422
423
424
# File 'lib/discordrb/webhooks/view.rb', line 422

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

#rowObject

Add a row component to the container.

See Also:

  • RowBuilder#initialize


390
391
392
# File 'lib/discordrb/webhooks/view.rb', line 390

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

#sectionObject

Add a section component to the container.



404
405
406
# File 'lib/discordrb/webhooks/view.rb', line 404

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

#separatorObject

Add a separator component to the container.



410
411
412
# File 'lib/discordrb/webhooks/view.rb', line 410

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

#text_displayObject

Add a text display component to the container.



416
417
418
# File 'lib/discordrb/webhooks/view.rb', line 416

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