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.
291 292 293 294 295 296 297 |
# File 'lib/discordrb/webhooks/view.rb', line 291 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.
324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/discordrb/webhooks/view.rb', line 324 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.
301 302 303 |
# File 'lib/discordrb/webhooks/view.rb', line 301 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.
310 311 312 |
# File 'lib/discordrb/webhooks/view.rb', line 310 def thumbnail(url:, id: nil, description: nil, spoiler: false) @accessory = { type: COMPONENT_TYPES[:thumbnail], id: id, media: { url: }, description: description, spoiler: spoiler }.compact end |