Class: Discordrb::Events::ModalSubmitEvent

Inherits:
ComponentEvent show all
Defined in:
lib/discordrb/events/interactions.rb

Overview

An event for when a user submits a modal.

Instance Attribute Summary collapse

Attributes inherited from ComponentEvent

#custom_id, #message

Attributes inherited from InteractionCreateEvent

#channel, #channel_id, #context, #interaction, #server, #server_id, #server_integration?, #type, #user, #user_integration?, #user_locale

Attributes inherited from Event

#bot

Instance Method Summary collapse

Methods inherited from InteractionCreateEvent

#defer, #defer_update, #delete_message, #delete_response, #edit_message, #edit_response, #get_component, #respond, #send_message, #show_modal, #update_message

Instance Attribute Details

#componentsArray<Component> (readonly)

Returns an array of partial component objects that were in the modal.

Returns:

  • (Array<Component>)

    an array of partial component objects that were in the modal.



410
411
412
# File 'lib/discordrb/events/interactions.rb', line 410

def components
  @components
end

#resolvedResolved (readonly)

Returns The resolved channels, roles, users, members, and attachments for the modal.

Returns:

  • (Resolved)

    The resolved channels, roles, users, members, and attachments for the modal.



413
414
415
# File 'lib/discordrb/events/interactions.rb', line 413

def resolved
  @resolved
end

Instance Method Details

#attachments(custom_id) ⇒ Array<Attachment>

Get the attachments that a user uploaded in this modal.

Parameters:

  • custom_id (String)

    The custom ID of the file upload component to get attachments for.

Returns:

  • (Array<Attachment>)

    the attachments that were uploaded to the file upload component.



440
441
442
# File 'lib/discordrb/events/interactions.rb', line 440

def attachments(custom_id)
  values(custom_id)&.map { |id| @resolved[:attachments][id.to_i] } || []
end

#value(custom_id) ⇒ String?

Get the value of an input passed to the modal.

Parameters:

  • custom_id (String)

    The custom ID of the component to look for.

Returns:

  • (String, nil)

    The selected value for the component.



426
427
428
# File 'lib/discordrb/events/interactions.rb', line 426

def value(custom_id)
  get_component(custom_id)&.value
end

#values(custom_id) ⇒ Array<String>?

Get the selected values from a select menu or file upload component.

Parameters:

  • custom_id (String)

    The custom ID of the component to look for.

Returns:

  • (Array<String>, nil)

    The values that were chosen for the component.



433
434
435
# File 'lib/discordrb/events/interactions.rb', line 433

def values(custom_id)
  get_component(custom_id)&.values
end