Class: Discordrb::Events::ApplicationCommandEvent

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

Overview

Event for ApplicationCommand interactions.

Direct Known Subclasses

AutocompleteEvent

Instance Attribute Summary collapse

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

#command_idInteger (readonly)

Returns The ID of the command.

Returns:

  • (Integer)

    The ID of the command.



178
179
180
# File 'lib/discordrb/events/interactions.rb', line 178

def command_id
  @command_id
end

#command_nameSymbol (readonly)

Returns The name of the command.

Returns:

  • (Symbol)

    The name of the command.



175
176
177
# File 'lib/discordrb/events/interactions.rb', line 175

def command_name
  @command_name
end

#optionsHash<Symbol, Object> (readonly)

Returns Arguments provided to the command, mapped as Name => Value.

Returns:

  • (Hash<Symbol, Object>)

    Arguments provided to the command, mapped as Name => Value.



190
191
192
# File 'lib/discordrb/events/interactions.rb', line 190

def options
  @options
end

#resolvedResolved (readonly)

Returns The resolved channels, roles, users, members, and attachments for this event.

Returns:

  • (Resolved)

    The resolved channels, roles, users, members, and attachments for this event.



187
188
189
# File 'lib/discordrb/events/interactions.rb', line 187

def resolved
  @resolved
end

#subcommandSymbol? (readonly)

Returns The name of the subcommand relevant to this event.

Returns:

  • (Symbol, nil)

    The name of the subcommand relevant to this event.



184
185
186
# File 'lib/discordrb/events/interactions.rb', line 184

def subcommand
  @subcommand
end

#subcommand_groupSymbol? (readonly)

Returns The name of the subcommand group relevant to this event.

Returns:

  • (Symbol, nil)

    The name of the subcommand group relevant to this event.



181
182
183
# File 'lib/discordrb/events/interactions.rb', line 181

def subcommand_group
  @subcommand_group
end

#target_idInteger? (readonly)

Returns The target of this command when it is a context command.

Returns:

  • (Integer, nil)

    The target of this command when it is a context command.



193
194
195
# File 'lib/discordrb/events/interactions.rb', line 193

def target_id
  @target_id
end

Instance Method Details

#global_command?true, false

Returns Whether or not the application command that was executed has been registered globally. If this is false, then the application command that was executed is only available in the invoking server.

Returns:

  • (true, false)

    Whether or not the application command that was executed has been registered globally. If this is false, then the application command that was executed is only available in the invoking server.



234
235
236
# File 'lib/discordrb/events/interactions.rb', line 234

def global_command?
  @command_server_id.nil?
end

#options_attachment(name) ⇒ Attachment

Parameters:

  • name (String)

    The name of the option.

Returns:



277
278
279
# File 'lib/discordrb/events/interactions.rb', line 277

def options_attachment(name)
  @resolved[:attachments][@options[name].to_i]
end

#options_channel(name) ⇒ Channel

Parameters:

  • name (String)

    The name of the option.

Returns:



265
266
267
# File 'lib/discordrb/events/interactions.rb', line 265

def options_channel(name)
  @resolved[:channels][@options[name].to_i]
end

#options_member(name) ⇒ Member

Parameters:

  • name (String)

    The name of the option.

Returns:



253
254
255
# File 'lib/discordrb/events/interactions.rb', line 253

def options_member(name)
  @resolved[:members][@options[name].to_i]
end

#options_mentionable(name) ⇒ Member, Role

Parameters:

  • name (String)

    The name of the option.

Returns:



271
272
273
# File 'lib/discordrb/events/interactions.rb', line 271

def options_mentionable(name)
  member(name) || role(name)
end

#options_role(name) ⇒ Role

Parameters:

  • name (String)

    The name of the option.

Returns:



259
260
261
# File 'lib/discordrb/events/interactions.rb', line 259

def options_role(name)
  @resolved[:roles][@options[name].to_i]
end

#options_user(name) ⇒ User

Parameters:

  • name (String)

    The name of the option.

Returns:



247
248
249
# File 'lib/discordrb/events/interactions.rb', line 247

def options_user(name)
  @resolved[:users][@options[name].to_i]
end

#targetMessage, ...

Returns The target of this command, for context commands.

Returns:

  • (Message, User, nil)

    The target of this command, for context commands.



239
240
241
242
243
# File 'lib/discordrb/events/interactions.rb', line 239

def target
  return nil unless @target_id

  @resolved.find { |data| data.key?(@target_id) }[@target_id]
end