Class: Discordrb::Webhooks::View::RowBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/webhooks/view.rb

Overview

This builder is used when constructing an ActionRow. Button and select menu components must be within an action row, but this can change in the future. A message can have 10 action rows, each action row can hold a weight of 5. Buttons have a weight of 1, and dropdowns have a weight of 5.

Instance Method Summary collapse

Instance Method Details

#button(style:, id: nil, label: nil, emoji: nil, custom_id: nil, disabled: nil, url: nil) ⇒ Object

Add a button to this action row.

Parameters:

  • style (Symbol, Integer)

    The button's style type. See BUTTON_STYLES

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the button component. This is not to be confused with the custom_id.

  • label (String, nil) (defaults to: nil)

    The text label for the button. Either a label or emoji must be provided.

  • emoji (#to_h, String, Integer) (defaults to: nil)

    An emoji ID, or unicode emoji to attach to the button. Can also be an object that responds to #to_h which returns a hash in the format of { id: Integer, name: string }.

  • custom_id (String) (defaults to: nil)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • disabled (true, false) (defaults to: nil)

    Whether this button is disabled and shown as greyed out.

  • url (String, nil) (defaults to: nil)

    The URL, when using a link style button.



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/discordrb/webhooks/view.rb', line 67

def button(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

  @components << { type: COMPONENT_TYPES[:button], id: id, label: label, emoji: emoji, style: style, custom_id: custom_id, disabled: disabled, url: url }.compact
end

#channel_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, types: nil) ⇒ Object

Add a select channel to this action row.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the channel select. This is not to be confused with the custom_id.

  • placeholder (String, nil) (defaults to: nil)

    Default text to show when no entries are selected.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum amount of values a user must select.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum amount of values a user can select.

  • disabled (true, false, nil) (defaults to: nil)

    Grey out the component to make it unusable.

  • types (Array<Symbol, Integer>, nil) (defaults to: nil)

    The channel types to include in the select menu.



145
146
147
148
149
150
151
# File 'lib/discordrb/webhooks/view.rb', line 145

def channel_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil, types: nil)
  builder = SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :channel_select, id: id).to_h

  builder[:channel_types] = types.map { |type| Discordrb::Channel::TYPES[type] || type } if types

  @components << builder
end

#mentionable_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil) ⇒ Object

Add a select mentionable to this action row.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the mentionable select. This is not to be confused with the custom_id.

  • placeholder (String, nil) (defaults to: nil)

    Default text to show when no entries are selected.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum amount of values a user must select.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum amount of values a user can select.

  • disabled (true, false, nil) (defaults to: nil)

    Grey out the component to make it unusable.



132
133
134
# File 'lib/discordrb/webhooks/view.rb', line 132

def mentionable_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil)
  @components << SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :mentionable_select, id: id).to_h
end

#role_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil) ⇒ Object

Add a select role to this action row.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the role select. This is not to be confused with the custom_id.

  • placeholder (String, nil) (defaults to: nil)

    Default text to show when no entries are selected.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum amount of values a user must select.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum amount of values a user can select.

  • disabled (true, false, nil) (defaults to: nil)

    Grey out the component to make it unusable.



120
121
122
# File 'lib/discordrb/webhooks/view.rb', line 120

def role_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil)
  @components << SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :role_select, id: id).to_h
end

#string_select(custom_id:, options: [], id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil) {|builder| ... } ⇒ Object Also known as: select_menu

Add a string select to this action row.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the string select. This is not to be confused with the custom_id.

  • options (Array<Hash>) (defaults to: [])

    Options that can be selected in this menu. Can also be provided via the yielded builder.

  • placeholder (String, nil) (defaults to: nil)

    Default text to show when no entries are selected.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum amount of values a user must select.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum amount of values a user can select.

  • disabled (true, false, nil) (defaults to: nil)

    Grey out the component to make it unusable.

Yield Parameters:



90
91
92
93
94
95
96
# File 'lib/discordrb/webhooks/view.rb', line 90

def string_select(custom_id:, options: [], id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil)
  builder = SelectMenuBuilder.new(custom_id, options, placeholder, min_values, max_values, disabled, select_type: :string_select, id: id)

  yield builder if block_given?

  @components << builder.to_h
end

#user_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil) ⇒ Object

Add a select user to this action row.

Parameters:

  • custom_id (String)

    Custom IDs are used to pass state to the events that are raised from interactions. There is a limit of 100 characters to each custom_id.

  • id (Integer, nil) (defaults to: nil)

    The unique 32-bit ID of the user select. This is not to be confused with the custom_id.

  • placeholder (String, nil) (defaults to: nil)

    Default text to show when no entries are selected.

  • min_values (Integer, nil) (defaults to: nil)

    The minimum amount of values a user must select.

  • max_values (Integer, nil) (defaults to: nil)

    The maximum amount of values a user can select.

  • disabled (true, false, nil) (defaults to: nil)

    Grey out the component to make it unusable.



108
109
110
# File 'lib/discordrb/webhooks/view.rb', line 108

def user_select(custom_id:, id: nil, placeholder: nil, min_values: nil, max_values: nil, disabled: nil)
  @components << SelectMenuBuilder.new(custom_id, [], placeholder, min_values, max_values, disabled, select_type: :user_select, id: id).to_h
end