Class: Discordrb::ApplicationCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/discordrb/data/interaction.rb

Overview

An ApplicationCommand for slash commands.

Defined Under Namespace

Classes: Permission

Constant Summary collapse

TYPES =

Command types. chat_input is a command that appears in the text input field. user and message types appear as context menus for the respective resource.

{
  chat_input: 1,
  user: 2,
  message: 3
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#application_idInteger (readonly)

Returns:



337
338
339
# File 'lib/discordrb/data/interaction.rb', line 337

def application_id
  @application_id
end

#default_permissiontrue, false (readonly)

Returns:

  • (true, false)


349
350
351
# File 'lib/discordrb/data/interaction.rb', line 349

def default_permission
  @default_permission
end

#descriptionString (readonly)

Returns:



346
347
348
# File 'lib/discordrb/data/interaction.rb', line 346

def description
  @description
end

#idInteger (readonly)

Returns:



355
356
357
# File 'lib/discordrb/data/interaction.rb', line 355

def id
  @id
end

#nameString (readonly)

Returns:



343
344
345
# File 'lib/discordrb/data/interaction.rb', line 343

def name
  @name
end

#optionsHash (readonly)

Returns:

  • (Hash)


352
353
354
# File 'lib/discordrb/data/interaction.rb', line 352

def options
  @options
end

#server_idInteger? (readonly)

Returns:



340
341
342
# File 'lib/discordrb/data/interaction.rb', line 340

def server_id
  @server_id
end

Instance Method Details

#deleteObject

Delete this application command.



398
399
400
# File 'lib/discordrb/data/interaction.rb', line 398

def delete
  @bot.delete_application_command(@id, server_id: @server_id)
end

#edit(name: nil, description: nil, default_permission: nil) {|, | ... } ⇒ Object

Parameters:

  • name (String) (defaults to: nil)

    The name to use for this command.

  • description (String) (defaults to: nil)

    The description of this command.

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

    Whether this command is available with default permissions.

Yield Parameters:

  • (OptionBuilder)
  • (PermissionBuilder)


392
393
394
# File 'lib/discordrb/data/interaction.rb', line 392

def edit(name: nil, description: nil, default_permission: nil, &block)
  @bot.edit_application_command(@id, server_id: @server_id, name: name, description: description, default_permission: default_permission, &block)
end

#mention(subcommand_group: nil, subcommand: nil) ⇒ String Also known as: to_s

Returns the layout to mention it in a message.

Parameters:

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

    The subcommand to mention.

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

    The subcommand group to mention.

Returns:

  • (String)

    the layout to mention it in a message



373
374
375
376
377
378
379
380
381
382
383
# File 'lib/discordrb/data/interaction.rb', line 373

def mention(subcommand_group: nil, subcommand: nil)
  if subcommand_group && subcommand
    "</#{name} #{subcommand_group} #{subcommand}:#{id}>"
  elsif subcommand_group
    "</#{name} #{subcommand_group}:#{id}>"
  elsif subcommand
    "</#{name} #{subcommand}:#{id}>"
  else
    "</#{name}:#{id}>"
  end
end

#permissions(server_id: nil) ⇒ Array<Permission>

Get the permission configuration for the this application command on a specific server.

Parameters:

  • server_id (Integer, String, nil) (defaults to: nil)

    The ID of the server to fetch command permissions for.

Returns:

  • (Array<Permission>)

    the permissions for this application command in the given server.



405
406
407
408
409
410
411
412
413
# File 'lib/discordrb/data/interaction.rb', line 405

def permissions(server_id: nil)
  raise ArgumentError, 'A server ID must be provided for global application commands' if @server_id.nil? && server_id.nil?

  response = JSON.parse(API::Application.get_application_command_permissions(@bot.token, @bot.profile.id, @server_id || server_id&.resolve_id, @id))
  response['permissions'].map { |permission| Permission.new(permission, response, @bot) }
rescue Discordrb::Errors::UnknownError
  # If there aren't any explicit overwrites configured for the command, the response is a 400.
  []
end