Class: Discordrb::Webhooks::View::SectionBuilder
- Inherits:
-
Object
- Object
- Discordrb::Webhooks::View::SectionBuilder
- Defined in:
- lib/discordrb/webhooks/view.rb
Overview
A section allows you to group together an accessory with text display components.
Instance Method Summary collapse
-
#button(style:, id: nil, label: nil, emoji: nil, custom_id: nil, disabled: nil, url: nil) ⇒ Object
Set the button for the section.
-
#initialize(id: nil) {|builder| ... } ⇒ SectionBuilder
constructor
Create a section component.
-
#text_display ⇒ Object
Add a text display component to this section.
-
#thumbnail(url:, id: nil, description: nil, spoiler: false) ⇒ Object
Set the thumbnail for the section.
Constructor Details
#initialize(id: nil) {|builder| ... } ⇒ SectionBuilder
Create a section component.
319 320 321 322 323 324 325 |
# File 'lib/discordrb/webhooks/view.rb', line 319 def initialize(id: nil) @id = id @accessory = nil @components = [] yield self if block_given? end |
Instance Method Details
#button(style:, id: nil, label: nil, emoji: nil, custom_id: nil, disabled: nil, url: nil) ⇒ Object
Set the button for the section. This is mutually exclusive with #thumbnail.
that responds to #to_h which returns a hash in the format of { id: Integer, name: string }.
There is a limit of 100 characters to each custom_id.
352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/discordrb/webhooks/view.rb', line 352 def (style:, id: nil, label: nil, emoji: nil, custom_id: nil, disabled: nil, url: nil) style = BUTTON_STYLES[style] || style emoji = case emoji when Integer, String emoji.to_i.positive? ? { id: emoji } : { name: emoji } else emoji&.to_h end @accessory = { type: COMPONENT_TYPES[:button], id: id, label: label, emoji: emoji, style: style, custom_id: custom_id, disabled: disabled, url: url }.compact end |
#text_display ⇒ Object
Add a text display component to this section.
329 330 331 |
# File 'lib/discordrb/webhooks/view.rb', line 329 def text_display(...) @components << TextDisplayBuilder.new(...) end |
#thumbnail(url:, id: nil, description: nil, spoiler: false) ⇒ Object
Set the thumbnail for the section. This is mutually exclusive with #button.
338 339 340 |
# File 'lib/discordrb/webhooks/view.rb', line 338 def thumbnail(url:, id: nil, description: nil, spoiler: false) @accessory = { type: COMPONENT_TYPES[:thumbnail], id: id, media: { url: }, description: description, spoiler: spoiler }.compact end |