Class: OnyxCord::Events::AutocompleteEvent

Inherits:
ApplicationCommandEvent show all
Defined in:
lib/onyxcord/events/interactions/autocomplete.rb

Overview

An event for an autocomplete option choice.

Instance Attribute Summary collapse

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

#bot

Instance Method Summary collapse

Methods inherited from ApplicationCommandEvent

#global_command?, #target

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

#focusedString (readonly)

Returns Name of the currently focused option.

Returns:

  • (String)

    Name of the currently focused option.



29
30
31
# File 'lib/onyxcord/events/interactions/autocomplete.rb', line 29

def focused
  @focused
end

#valueString, ... (readonly)

Returns The current value typed by the user (if any).

Returns:

  • (String, Integer, Float, nil)

    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.

Parameters:

  • name (String)

    The display name of the choice.

  • value (String, Integer, Float)

    The value sent to the bot when selected.



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.

Parameters:



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.

Parameters:

  • choices (Array<Hash>, Hash)

    Autocomplete choices to return. When a Hash, keys are names and values are the choice values. When an Array, each element is a Hash with :name and :value keys.



58
59
60
# File 'lib/onyxcord/events/interactions/autocomplete.rb', line 58

def respond(choices:)
  @interaction.show_autocomplete_choices(choices || [])
end