Class: OnyxCord::Events::AutocompleteEvent
- Inherits:
-
ApplicationCommandEvent
- Object
- Event
- InteractionCreateEvent
- ApplicationCommandEvent
- OnyxCord::Events::AutocompleteEvent
- Defined in:
- lib/onyxcord/events/interactions/autocomplete.rb
Overview
An event for an autocomplete option choice.
Instance Attribute Summary collapse
-
#focused ⇒ String
readonly
Name of the currently focused option.
-
#value ⇒ String, ...
readonly
The current value typed by the user (if any).
Attributes inherited from ApplicationCommandEvent
#command_id, #command_name, #options, #resolved, #subcommand, #subcommand_group, #target_id
Attributes inherited from InteractionCreateEvent
#channel, #channel_id, #context, #interaction, #server, #server_id, #server_integration?, #type, #user, #user_integration?, #user_locale
Attributes inherited from Event
Instance Method Summary collapse
-
#add_choice(name, value) ⇒ Object
Convenience method to add a single choice and respond.
-
#add_choices(pairs) ⇒ Object
Convenience method to respond with multiple name/value pairs.
-
#respond(choices:) ⇒ Object
Respond to this interaction with autocomplete choices.
Methods inherited from ApplicationCommandEvent
Methods inherited from InteractionCreateEvent
#defer, #defer_update, #delete_message, #delete_response, #edit_message, #edit_response, #get_component, #send_message, #show_modal, #update_message
Instance Attribute Details
#focused ⇒ String (readonly)
Returns Name of the currently focused option.
29 30 31 |
# File 'lib/onyxcord/events/interactions/autocomplete.rb', line 29 def focused @focused end |
#value ⇒ String, ... (readonly)
Returns The current value typed by the user (if any).
32 33 34 |
# File 'lib/onyxcord/events/interactions/autocomplete.rb', line 32 def value @value end |
Instance Method Details
#add_choice(name, value) ⇒ Object
Convenience method to add a single choice and respond.
65 66 67 |
# File 'lib/onyxcord/events/interactions/autocomplete.rb', line 65 def add_choice(name, value) respond(choices: [{ name: name.to_s, value: value }]) end |
#add_choices(pairs) ⇒ Object
Convenience method to respond with multiple name/value pairs.
71 72 73 |
# File 'lib/onyxcord/events/interactions/autocomplete.rb', line 71 def add_choices(pairs) respond(choices: pairs.map { |n, v| { name: n.to_s, value: v } }) end |
#respond(choices:) ⇒ Object
Respond to this interaction with autocomplete choices.
58 59 60 |
# File 'lib/onyxcord/events/interactions/autocomplete.rb', line 58 def respond(choices:) @interaction.show_autocomplete_choices(choices || []) end |