Class: Rubord::Button
- Inherits:
-
Object
- Object
- Rubord::Button
- Defined in:
- lib/rubord/components/button.rb
Overview
Represents a Discord interactive button component.
Buttons are interactive elements that users can click to trigger actions. They can be used in messages, modals, and action rows.
Instance Attribute Summary collapse
-
#custom_id ⇒ String?
Developer-defined identifier for the button.
-
#disabled ⇒ Boolean
Whether the button is disabled.
-
#emoji ⇒ Hash?
Emoji to display on the button.
-
#label ⇒ String
Text displayed on the button (max 80 characters).
-
#style ⇒ Integer
Button style (1-5).
-
#type ⇒ Integer
Component type (always 2 for buttons).
-
#url ⇒ String?
URL for link buttons (style 5).
Instance Method Summary collapse
-
#initialize(label: nil, style: 1, custom_id: nil, url: nil, disabled: false, emoji: nil) ⇒ Button
constructor
Creates a new button component.
-
#to_h ⇒ Hash
Converts the button to a Discord API-compatible hash.
Constructor Details
#initialize(label: nil, style: 1, custom_id: nil, url: nil, disabled: false, emoji: nil) ⇒ Button
Creates a new button component.
83 84 85 86 87 88 89 90 91 |
# File 'lib/rubord/components/button.rb', line 83 def initialize(label: nil, style: 1, custom_id: nil, url: nil, disabled: false, emoji: nil) @type = 2 @style = style @label = label @custom_id = custom_id @url = url @disabled = disabled @emoji = emoji end |
Instance Attribute Details
#custom_id ⇒ String?
Returns Developer-defined identifier for the button. Required for non-link buttons, must be unique per message.
42 43 44 |
# File 'lib/rubord/components/button.rb', line 42 def custom_id @custom_id end |
#disabled ⇒ Boolean
Returns Whether the button is disabled.
48 49 50 |
# File 'lib/rubord/components/button.rb', line 48 def disabled @disabled end |
#emoji ⇒ Hash?
Returns Emoji to display on the button. Format: ‘“emoji_name”, id: “emoji_id”, animated: false`.
52 53 54 |
# File 'lib/rubord/components/button.rb', line 52 def emoji @emoji end |
#label ⇒ String
Returns Text displayed on the button (max 80 characters).
38 39 40 |
# File 'lib/rubord/components/button.rb', line 38 def label @label end |
#style ⇒ Integer
Returns Button style (1-5).
-
1: Primary (blurple)
-
2: Secondary (grey)
-
3: Success (green)
-
4: Danger (red)
-
5: Link (grey, navigates to URL).
35 36 37 |
# File 'lib/rubord/components/button.rb', line 35 def style @style end |
#type ⇒ Integer
Returns Component type (always 2 for buttons).
27 28 29 |
# File 'lib/rubord/components/button.rb', line 27 def type @type end |
#url ⇒ String?
Returns URL for link buttons (style 5).
45 46 47 |
# File 'lib/rubord/components/button.rb', line 45 def url @url end |
Instance Method Details
#to_h ⇒ Hash
Converts the button to a Discord API-compatible hash.
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/rubord/components/button.rb', line 101 def to_h h = { type: @type, style: @style, label: @label, disabled: @disabled } h[:custom_id] = @custom_id if @custom_id h[:url] = @url if @url h[:emoji] = @emoji if @emoji h end |