Class: Discordrb::Components::Button

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/data/component.rb

Overview

An interactable button component.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#custom_idString (readonly)

Returns the custom ID of the button.

Returns:

  • (String)

    the custom ID of the button.



101
102
103
# File 'lib/discordrb/data/component.rb', line 101

def custom_id
  @custom_id
end

#disabledtrue, false (readonly)

Returns whether or not the button is disabled.

Returns:

  • (true, false)

    whether or not the button is disabled.



104
105
106
# File 'lib/discordrb/data/component.rb', line 104

def disabled
  @disabled
end

#emojiEmoji? (readonly)

Returns the custom emoji of the button component.

Returns:

  • (Emoji, nil)

    the custom emoji of the button component.



110
111
112
# File 'lib/discordrb/data/component.rb', line 110

def emoji
  @emoji
end

#idInteger (readonly)

Returns the numeric identifier of the button.

Returns:

  • (Integer)

    the numeric identifier of the button.



92
93
94
# File 'lib/discordrb/data/component.rb', line 92

def id
  @id
end

#labelString (readonly)

Returns the label of the button.

Returns:

  • (String)

    the label of the button.



95
96
97
# File 'lib/discordrb/data/component.rb', line 95

def label
  @label
end

#styleInteger (readonly)

Returns the style of the button.

Returns:

  • (Integer)

    the style of the button.



98
99
100
# File 'lib/discordrb/data/component.rb', line 98

def style
  @style
end

#urlString? (readonly)

Returns the URL of the button if applicable.

Returns:

  • (String, nil)

    the URL of the button if applicable.



107
108
109
# File 'lib/discordrb/data/component.rb', line 107

def url
  @url
end

Instance Method Details

#await_click(key, **attributes, &block) ⇒ Object

Await a button click.



141
142
143
# File 'lib/discordrb/data/component.rb', line 141

def await_click(key, **attributes, &block)
  @bot.add_await(key, Discordrb::Events::ButtonEvent, { custom_id: @custom_id }.merge!(attributes), &block)
end

#await_click!(**attributes, &block) ⇒ Object

Await a button click, blocking.



146
147
148
# File 'lib/discordrb/data/component.rb', line 146

def await_click!(**attributes, &block)
  @bot.add_await!(Discordrb::Events::ButtonEvent, { custom_id: @custom_id }.merge!(attributes), &block)
end

#danger?true, false

Returns whether the button denotes a dangerous action in the group.

Returns:

  • (true, false)

    whether the button denotes a dangerous action in the group.



134
135
136
137
138
# File 'lib/discordrb/data/component.rb', line 134

Webhooks::View::BUTTON_STYLES.each do |name, value|
  define_method("#{name}?") do
    @style == value
  end
end

#link?true, false

Returns whether the button is a container for a URL that will open upon click.

Returns:

  • (true, false)

    whether the button is a container for a URL that will open upon click.



134
135
136
137
138
# File 'lib/discordrb/data/component.rb', line 134

Webhooks::View::BUTTON_STYLES.each do |name, value|
  define_method("#{name}?") do
    @style == value
  end
end

#primary?true, false

Returns whether the button is a primary option in the group.

Returns:

  • (true, false)

    whether the button is a primary option in the group.



134
135
136
137
138
# File 'lib/discordrb/data/component.rb', line 134

Webhooks::View::BUTTON_STYLES.each do |name, value|
  define_method("#{name}?") do
    @style == value
  end
end

#secondary?true, false

Returns whether the button denotes a secondary option in the group.

Returns:

  • (true, false)

    whether the button denotes a secondary option in the group.



134
135
136
137
138
# File 'lib/discordrb/data/component.rb', line 134

Webhooks::View::BUTTON_STYLES.each do |name, value|
  define_method("#{name}?") do
    @style == value
  end
end

#success?true, false

Returns whether the button denotes a success action in the group.

Returns:

  • (true, false)

    whether the button denotes a success action in the group.



134
135
136
137
138
# File 'lib/discordrb/data/component.rb', line 134

Webhooks::View::BUTTON_STYLES.each do |name, value|
  define_method("#{name}?") do
    @style == value
  end
end