Class: DiscordRDA::Subcommand
- Inherits:
-
Object
- Object
- DiscordRDA::Subcommand
- Defined in:
- lib/discord_rda/interactions/command_system.rb
Overview
Represents a subcommand
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
Instance Method Summary collapse
- #check_permissions(context) ⇒ Object
-
#execute(context) ⇒ Object
Execute subcommand.
-
#initialize(name:, description:, options:, permissions:, handler:, parent:) ⇒ Subcommand
constructor
A new instance of Subcommand.
- #to_option_format ⇒ Object
Constructor Details
#initialize(name:, description:, options:, permissions:, handler:, parent:) ⇒ Subcommand
Returns a new instance of Subcommand.
329 330 331 332 333 334 335 336 |
# File 'lib/discord_rda/interactions/command_system.rb', line 329 def initialize(name:, description:, options:, permissions:, handler:, parent:) @name = name.to_s @description = description @options = @permissions = @handler = handler @parent = parent end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
327 328 329 |
# File 'lib/discord_rda/interactions/command_system.rb', line 327 def description @description end |
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
327 328 329 |
# File 'lib/discord_rda/interactions/command_system.rb', line 327 def handler @handler end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
327 328 329 |
# File 'lib/discord_rda/interactions/command_system.rb', line 327 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
327 328 329 |
# File 'lib/discord_rda/interactions/command_system.rb', line 327 def @options end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
327 328 329 |
# File 'lib/discord_rda/interactions/command_system.rb', line 327 def parent @parent end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
327 328 329 |
# File 'lib/discord_rda/interactions/command_system.rb', line 327 def @permissions end |
Instance Method Details
#check_permissions(context) ⇒ Object
349 350 351 352 353 354 |
# File 'lib/discord_rda/interactions/command_system.rb', line 349 def (context) return true if .empty? return true unless context.member .all? { |perm| context.member.&.send("#{perm}?") } end |
#execute(context) ⇒ Object
Execute subcommand
340 341 342 343 344 345 346 347 |
# File 'lib/discord_rda/interactions/command_system.rb', line 340 def execute(context) # Check permissions unless (context) return context.respond(content: "You don't have permission to use this subcommand.", ephemeral: true) end handler.call(context) end |
#to_option_format ⇒ Object
356 357 358 359 360 361 362 363 |
# File 'lib/discord_rda/interactions/command_system.rb', line 356 def to_option_format { type: 1, # SUB_COMMAND name: name, description: description, options: } end |