Class: DiscordRDA::Components::Button
- Defined in:
- lib/discord_rda/interactions/components.rb
Overview
Button component
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.danger(label:, custom_id:, **options) ⇒ Object
Create a danger (red) button.
-
.link(label:, url:, **options) ⇒ Object
Create a link button.
-
.primary(label:, custom_id:, **options) ⇒ Object
Create a primary (blurple) button.
-
.secondary(label:, custom_id:, **options) ⇒ Object
Create a secondary (grey) button.
-
.success(label:, custom_id:, **options) ⇒ Object
Create a success (green) button.
Instance Method Summary collapse
-
#initialize(style:, label: nil, custom_id: nil, url: nil, emoji: nil, sku_id: nil, disabled: false) ⇒ Button
constructor
A new instance of Button.
Methods inherited from Base
Constructor Details
#initialize(style:, label: nil, custom_id: nil, url: nil, emoji: nil, sku_id: nil, disabled: false) ⇒ Button
Returns a new instance of Button.
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/discord_rda/interactions/components.rb', line 129 def initialize(style:, label: nil, custom_id: nil, url: nil, emoji: nil, sku_id: nil, disabled: false) style_val = BUTTON_STYLES[style] || style data = { style: style_val, disabled: disabled } data[:label] = label if label data[:custom_id] = custom_id if custom_id data[:url] = url if url && style_val == 5 data[:emoji] = emoji.is_a?(String) ? { name: emoji } : emoji if emoji data[:sku_id] = sku_id if sku_id && style_val == 6 super(:button, data) end |
Class Method Details
.danger(label:, custom_id:, **options) ⇒ Object
Create a danger (red) button
166 167 168 |
# File 'lib/discord_rda/interactions/components.rb', line 166 def self.danger(label:, custom_id:, **) new(style: :danger, label: label, custom_id: custom_id, **) end |
.link(label:, url:, **options) ⇒ Object
Create a link button
173 174 175 |
# File 'lib/discord_rda/interactions/components.rb', line 173 def self.link(label:, url:, **) new(style: :link, label: label, url: url, **) end |
.primary(label:, custom_id:, **options) ⇒ Object
Create a primary (blurple) button
145 146 147 |
# File 'lib/discord_rda/interactions/components.rb', line 145 def self.primary(label:, custom_id:, **) new(style: :primary, label: label, custom_id: custom_id, **) end |
.secondary(label:, custom_id:, **options) ⇒ Object
Create a secondary (grey) button
152 153 154 |
# File 'lib/discord_rda/interactions/components.rb', line 152 def self.secondary(label:, custom_id:, **) new(style: :secondary, label: label, custom_id: custom_id, **) end |
.success(label:, custom_id:, **options) ⇒ Object
Create a success (green) button
159 160 161 |
# File 'lib/discord_rda/interactions/components.rb', line 159 def self.success(label:, custom_id:, **) new(style: :success, label: label, custom_id: custom_id, **) end |