Class: Discorb::Button
Overview
Represents a button component.
Instance Attribute Summary collapse
-
#custom_id ⇒ String
The custom ID of the button.
-
#disabled ⇒ Boolean
(also: #disabled?)
Whether the button is disabled.
-
#emoji ⇒ Discorb::Emoji
The emoji of the button.
-
#label ⇒ String
The label of the button.
-
#style ⇒ :primary, ...
The style of the button.
-
#url ⇒ String
The URL of the button.
Instance Method Summary collapse
-
#initialize(label, style = :primary, emoji: nil, custom_id: nil, url: nil, disabled: false) ⇒ Button
constructor
Initialize a new button.
-
#to_hash ⇒ Hash
Converts the button to a hash.
Methods inherited from Component
Constructor Details
#initialize(label, style = :primary, emoji: nil, custom_id: nil, url: nil, disabled: false) ⇒ Button
Initialize a new button.
80 81 82 83 84 85 86 87 |
# File 'lib/discorb/components.rb', line 80 def initialize(label, style = :primary, emoji: nil, custom_id: nil, url: nil, disabled: false) @label = label @style = style @emoji = emoji @custom_id = custom_id @url = url @disabled = disabled end |
Instance Attribute Details
#custom_id ⇒ String
Returns The custom ID of the button.
Won't be used if the style is :link
.
54 55 56 |
# File 'lib/discorb/components.rb', line 54 def custom_id @custom_id end |
#disabled ⇒ Boolean Also known as: disabled?
Returns Whether the button is disabled.
59 60 61 |
# File 'lib/discorb/components.rb', line 59 def disabled @disabled end |
#emoji ⇒ Discorb::Emoji
Returns The emoji of the button.
51 52 53 |
# File 'lib/discorb/components.rb', line 51 def emoji @emoji end |
#label ⇒ String
Returns The label of the button.
47 48 49 |
# File 'lib/discorb/components.rb', line 47 def label @label end |
#style ⇒ :primary, ...
Returns The style of the button.
49 50 51 |
# File 'lib/discorb/components.rb', line 49 def style @style end |
#url ⇒ String
Returns The URL of the button.
Only used when the style is :link
.
57 58 59 |
# File 'lib/discorb/components.rb', line 57 def url @url end |
Instance Method Details
#to_hash ⇒ Hash
Converts the button to a hash.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/discorb/components.rb', line 95 def to_hash if @style == :link { type: 2, label: @label, style: self.class.styles[@style], url: @url, emoji: hash_emoji(@emoji), disabled: @disabled, } else { type: 2, label: @label, style: self.class.styles[@style], custom_id: @custom_id, emoji: hash_emoji(@emoji), disabled: @disabled, } end end |