Class: DiscordRDA::CommandContext
- Inherits:
-
Object
- Object
- DiscordRDA::CommandContext
- Defined in:
- lib/discord_rda/interactions/command_system.rb
Overview
Context for command execution
Instance Attribute Summary collapse
-
#channel ⇒ Channel
readonly
The channel where the command was invoked.
-
#guild ⇒ Guild?
readonly
The guild where the command was invoked.
-
#interaction ⇒ Interaction
readonly
The interaction.
-
#member ⇒ Member?
readonly
The member who invoked the command.
-
#system ⇒ CommandSystem
readonly
The command system.
-
#user ⇒ User
readonly
The user who invoked the command.
Instance Method Summary collapse
-
#channel_id ⇒ String
Get channel ID.
-
#defer(ephemeral: false) ⇒ Object
Defer the response.
-
#dm? ⇒ Boolean
Check if this is a DM context.
-
#followup(content = nil, **options, &block) ⇒ Object
Send a followup message.
-
#guild? ⇒ Boolean
Check if this is a guild context.
-
#guild_id ⇒ String?
Get guild ID.
-
#initialize(interaction, system) ⇒ CommandContext
constructor
A new instance of CommandContext.
-
#option(name) ⇒ Object
Get a specific option value.
-
#options ⇒ Hash
Get command options.
-
#respond(content = nil, **options, &block) ⇒ Object
Respond to the interaction.
-
#subcommand ⇒ String?
Get subcommand name.
-
#subcommand_group ⇒ String?
Get subcommand group name.
Constructor Details
#initialize(interaction, system) ⇒ CommandContext
Returns a new instance of CommandContext.
398 399 400 401 402 403 404 405 |
# File 'lib/discord_rda/interactions/command_system.rb', line 398 def initialize(interaction, system) @interaction = interaction @system = system @user = interaction.user @member = interaction.member @guild = nil # Would need to fetch from cache @channel = nil # Would need to fetch from cache end |
Instance Attribute Details
#channel ⇒ Channel (readonly)
Returns The channel where the command was invoked.
396 397 398 |
# File 'lib/discord_rda/interactions/command_system.rb', line 396 def channel @channel end |
#guild ⇒ Guild? (readonly)
Returns The guild where the command was invoked.
393 394 395 |
# File 'lib/discord_rda/interactions/command_system.rb', line 393 def guild @guild end |
#interaction ⇒ Interaction (readonly)
Returns The interaction.
381 382 383 |
# File 'lib/discord_rda/interactions/command_system.rb', line 381 def interaction @interaction end |
#member ⇒ Member? (readonly)
Returns The member who invoked the command.
390 391 392 |
# File 'lib/discord_rda/interactions/command_system.rb', line 390 def member @member end |
#system ⇒ CommandSystem (readonly)
Returns The command system.
384 385 386 |
# File 'lib/discord_rda/interactions/command_system.rb', line 384 def system @system end |
#user ⇒ User (readonly)
Returns The user who invoked the command.
387 388 389 |
# File 'lib/discord_rda/interactions/command_system.rb', line 387 def user @user end |
Instance Method Details
#channel_id ⇒ String
Get channel ID
448 449 450 |
# File 'lib/discord_rda/interactions/command_system.rb', line 448 def channel_id interaction.channel_id&.to_s end |
#defer(ephemeral: false) ⇒ Object
Defer the response
461 462 463 |
# File 'lib/discord_rda/interactions/command_system.rb', line 461 def defer(ephemeral: false) interaction.defer(ephemeral: ephemeral) end |
#dm? ⇒ Boolean
Check if this is a DM context
480 481 482 |
# File 'lib/discord_rda/interactions/command_system.rb', line 480 def dm? guild_id.nil? end |
#followup(content = nil, **options, &block) ⇒ Object
Send a followup message
468 469 470 |
# File 'lib/discord_rda/interactions/command_system.rb', line 468 def followup(content = nil, **, &block) interaction.followup(content, **, &block) end |
#guild? ⇒ Boolean
Check if this is a guild context
474 475 476 |
# File 'lib/discord_rda/interactions/command_system.rb', line 474 def guild? !guild_id.nil? end |
#guild_id ⇒ String?
Get guild ID
442 443 444 |
# File 'lib/discord_rda/interactions/command_system.rb', line 442 def guild_id interaction.guild_id&.to_s end |
#option(name) ⇒ Object
Get a specific option value
416 417 418 |
# File 'lib/discord_rda/interactions/command_system.rb', line 416 def option(name) [name.to_s] end |
#options ⇒ Hash
Get command options
409 410 411 |
# File 'lib/discord_rda/interactions/command_system.rb', line 409 def interaction. || {} end |
#respond(content = nil, **options, &block) ⇒ Object
Respond to the interaction
455 456 457 |
# File 'lib/discord_rda/interactions/command_system.rb', line 455 def respond(content = nil, **, &block) interaction.respond(content, **, &block) end |
#subcommand ⇒ String?
Get subcommand name
422 423 424 425 426 427 428 |
# File 'lib/discord_rda/interactions/command_system.rb', line 422 def subcommand data = interaction.command_data return nil unless data && data['options'] sub = data['options'].find { |opt| opt['type'] == 1 } sub&.dig('name') end |
#subcommand_group ⇒ String?
Get subcommand group name
432 433 434 435 436 437 438 |
# File 'lib/discord_rda/interactions/command_system.rb', line 432 def subcommand_group data = interaction.command_data return nil unless data && data['options'] group = data['options'].find { |opt| opt['type'] == 2 } group&.dig('name') end |