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:



416
417
418
# File 'lib/discordrb/data/interaction.rb', line 416

def application_id
  @application_id
end

#contextsArray<Integer> (readonly)

Returns:



440
441
442
# File 'lib/discordrb/data/interaction.rb', line 440

def contexts
  @contexts
end

#default_permissiontrue, false (readonly)

Returns:

  • (true, false)


428
429
430
# File 'lib/discordrb/data/interaction.rb', line 428

def default_permission
  @default_permission
end

#descriptionString (readonly)

Returns:



425
426
427
# File 'lib/discordrb/data/interaction.rb', line 425

def description
  @description
end

#idInteger (readonly)

Returns:



434
435
436
# File 'lib/discordrb/data/interaction.rb', line 434

def id
  @id
end

#integration_typesArray<Integer> (readonly)

Returns:



443
444
445
# File 'lib/discordrb/data/interaction.rb', line 443

def integration_types
  @integration_types
end

#nameString (readonly)

Returns:



422
423
424
# File 'lib/discordrb/data/interaction.rb', line 422

def name
  @name
end

#nsfwtrue, false (readonly)

Returns:

  • (true, false)


437
438
439
# File 'lib/discordrb/data/interaction.rb', line 437

def nsfw
  @nsfw
end

#optionsHash (readonly)

Returns:

  • (Hash)


431
432
433
# File 'lib/discordrb/data/interaction.rb', line 431

def options
  @options
end

#server_idInteger? (readonly)

Returns:



419
420
421
# File 'lib/discordrb/data/interaction.rb', line 419

def server_id
  @server_id
end

Instance Method Details

#deleteObject

Delete this application command.



490
491
492
# File 'lib/discordrb/data/interaction.rb', line 490

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

#edit(name: nil, description: nil, default_permission: nil, nsfw: 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.

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

    Whether this command should be marked as age-restricted.

Yield Parameters:

  • (OptionBuilder)
  • (PermissionBuilder)


484
485
486
# File 'lib/discordrb/data/interaction.rb', line 484

def edit(name: nil, description: nil, default_permission: nil, nsfw: nil, &block)
  @bot.edit_application_command(@id, server_id: @server_id, name: name, description: description, default_permission: default_permission, nsfw: nsfw, &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



464
465
466
467
468
469
470
471
472
473
474
# File 'lib/discordrb/data/interaction.rb', line 464

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 this application command in 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.



497
498
499
500
501
502
503
504
505
# File 'lib/discordrb/data/interaction.rb', line 497

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