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_input
is a command that appears in the text input field.user
andmessage
types appear as context menus for the respective resource. { chat_input: 1, user: 2, message: 3 }.freeze
Instance Attribute Summary collapse
- #application_id ⇒ Integer readonly
- #default_permission ⇒ true, false readonly
- #description ⇒ String readonly
- #id ⇒ Integer readonly
- #name ⇒ String 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) {|, | ... } ⇒ 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 the this application command on a specific server.
Instance Attribute Details
#application_id ⇒ Integer (readonly)
337 338 339 |
# File 'lib/discordrb/data/interaction.rb', line 337 def application_id @application_id end |
#default_permission ⇒ true, false (readonly)
349 350 351 |
# File 'lib/discordrb/data/interaction.rb', line 349 def @default_permission end |
#description ⇒ String (readonly)
346 347 348 |
# File 'lib/discordrb/data/interaction.rb', line 346 def description @description end |
#id ⇒ Integer (readonly)
355 356 357 |
# File 'lib/discordrb/data/interaction.rb', line 355 def id @id end |
#name ⇒ String (readonly)
343 344 345 |
# File 'lib/discordrb/data/interaction.rb', line 343 def name @name end |
#options ⇒ Hash (readonly)
352 353 354 |
# File 'lib/discordrb/data/interaction.rb', line 352 def @options end |
#server_id ⇒ Integer? (readonly)
340 341 342 |
# File 'lib/discordrb/data/interaction.rb', line 340 def server_id @server_id end |
Instance Method Details
#delete ⇒ Object
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
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: , &block) end |
#mention(subcommand_group: nil, subcommand: nil) ⇒ String Also known as: to_s
Returns 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.
405 406 407 408 409 410 411 412 413 |
# File 'lib/discordrb/data/interaction.rb', line 405 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 |