Class: Discordrb::ApplicationCommand
- Inherits:
-
Object
- Object
- Discordrb::ApplicationCommand
- 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_inputis a command that appears in the text input field.userandmessagetypes appear as context menus for the respective resource. { chat_input: 1, user: 2, message: 3 }.freeze
Instance Attribute Summary collapse
- #application_id ⇒ Integer readonly
- #contexts ⇒ Array<Integer> readonly
- #default_permission ⇒ true, false readonly
- #description ⇒ String readonly
- #id ⇒ Integer readonly
- #integration_types ⇒ Array<Integer> readonly
- #name ⇒ String readonly
- #nsfw ⇒ true, false readonly
- #options ⇒ Hash readonly
- #server_id ⇒ Integer? readonly
Instance Method Summary collapse
-
#delete ⇒ Object
Delete this application command.
- #edit(name: nil, description: nil, default_permission: nil, nsfw: nil) {|, | ... } ⇒ Object
-
#mention(subcommand_group: nil, subcommand: nil) ⇒ String
(also: #to_s)
The layout to mention it in a message.
-
#permissions(server_id: nil) ⇒ Array<Permission>
Get the permission configuration for this application command in a specific server.
Instance Attribute Details
#application_id ⇒ Integer (readonly)
423 424 425 |
# File 'lib/discordrb/data/interaction.rb', line 423 def application_id @application_id end |
#contexts ⇒ Array<Integer> (readonly)
447 448 449 |
# File 'lib/discordrb/data/interaction.rb', line 447 def contexts @contexts end |
#default_permission ⇒ true, false (readonly)
435 436 437 |
# File 'lib/discordrb/data/interaction.rb', line 435 def @default_permission end |
#description ⇒ String (readonly)
432 433 434 |
# File 'lib/discordrb/data/interaction.rb', line 432 def description @description end |
#id ⇒ Integer (readonly)
441 442 443 |
# File 'lib/discordrb/data/interaction.rb', line 441 def id @id end |
#integration_types ⇒ Array<Integer> (readonly)
450 451 452 |
# File 'lib/discordrb/data/interaction.rb', line 450 def integration_types @integration_types end |
#name ⇒ String (readonly)
429 430 431 |
# File 'lib/discordrb/data/interaction.rb', line 429 def name @name end |
#nsfw ⇒ true, false (readonly)
444 445 446 |
# File 'lib/discordrb/data/interaction.rb', line 444 def nsfw @nsfw end |
#options ⇒ Hash (readonly)
438 439 440 |
# File 'lib/discordrb/data/interaction.rb', line 438 def @options end |
#server_id ⇒ Integer? (readonly)
426 427 428 |
# File 'lib/discordrb/data/interaction.rb', line 426 def server_id @server_id end |
Instance Method Details
#delete ⇒ Object
Delete this application command.
497 498 499 |
# File 'lib/discordrb/data/interaction.rb', line 497 def delete @bot.delete_application_command(@id, server_id: @server_id) end |
#edit(name: nil, description: nil, default_permission: nil, nsfw: nil) {|, | ... } ⇒ Object
491 492 493 |
# File 'lib/discordrb/data/interaction.rb', line 491 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: , 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.
471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/discordrb/data/interaction.rb', line 471 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.
504 505 506 507 508 509 510 511 512 |
# File 'lib/discordrb/data/interaction.rb', line 504 def (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.(@bot.token, @bot.profile.id, @server_id || server_id&.resolve_id, @id)) response['permissions'].map { || Permission.new(, response, @bot) } rescue Discordrb::Errors::UnknownError # If there aren't any explicit overwrites configured for the command, the response is a 400. [] end |