Class: Discordrb::Events::ApplicationCommandEvent
- Inherits:
-
InteractionCreateEvent
- Object
- Event
- InteractionCreateEvent
- Discordrb::Events::ApplicationCommandEvent
- Defined in:
- lib/discordrb/events/interactions.rb
Overview
Event for ApplicationCommand interactions.
Defined Under Namespace
Classes: Resolved
Instance Attribute Summary collapse
-
#command_id ⇒ Integer
readonly
The ID of the command.
-
#command_name ⇒ String
readonly
The name of the command.
-
#options ⇒ Hash<Symbol, Object>
readonly
Arguments provided to the command, mapped as
Name => Value
. - #resolved ⇒ Resolved readonly
-
#subcommand ⇒ String?
readonly
The name of the subcommand relevant to this event.
-
#subcommand_group ⇒ String?
readonly
The name of the subcommand group relevant to this event.
-
#target_id ⇒ Integer?
readonly
The target of this command when it is a context command.
Attributes inherited from InteractionCreateEvent
#channel, #channel_id, #interaction, #server, #server_id, #type, #user
Attributes inherited from Event
Instance Method Summary collapse
-
#initialize(data, bot) ⇒ ApplicationCommandEvent
constructor
A new instance of ApplicationCommandEvent.
- #options_attachment(name) ⇒ Attachment
- #options_channel(name) ⇒ Channel
- #options_member(name) ⇒ Member
- #options_mentionable(name) ⇒ Member, Role
- #options_role(name) ⇒ Role
- #options_user(name) ⇒ User
-
#target ⇒ Message, ...
The target of this command, for context commands.
Methods inherited from InteractionCreateEvent
#defer, #defer_update, #delete_message, #delete_response, #edit_message, #edit_response, #get_component, #respond, #send_message, #show_modal, #update_message
Constructor Details
#initialize(data, bot) ⇒ ApplicationCommandEvent
Returns a new instance of ApplicationCommandEvent.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/discordrb/events/interactions.rb', line 156 def initialize(data, bot) super command_data = data['data'] @command_id = command_data['id'] @command_name = command_data['name'].to_sym @target_id = command_data['target_id']&.to_i @resolved = Resolved.new({}, {}, {}, {}, {}, {}) process_resolved(command_data['resolved']) if command_data['resolved'] = command_data['options'] || [] if .empty? @options = {} return end case [0]['type'] when 2 = [0] @subcommand_group = ['name'].to_sym @subcommand = ['options'][0]['name'].to_sym = ['options'][0]['options'] when 1 = [0] @subcommand = ['name'].to_sym = ['options'] end @options = ( || {}) end |
Instance Attribute Details
#command_id ⇒ Integer (readonly)
Returns The ID of the command.
139 140 141 |
# File 'lib/discordrb/events/interactions.rb', line 139 def command_id @command_id end |
#command_name ⇒ String (readonly)
Returns The name of the command.
136 137 138 |
# File 'lib/discordrb/events/interactions.rb', line 136 def command_name @command_name end |
#options ⇒ Hash<Symbol, Object> (readonly)
Returns Arguments provided to the command, mapped as Name => Value
.
151 152 153 |
# File 'lib/discordrb/events/interactions.rb', line 151 def @options end |
#resolved ⇒ Resolved (readonly)
148 149 150 |
# File 'lib/discordrb/events/interactions.rb', line 148 def resolved @resolved end |
#subcommand ⇒ String? (readonly)
Returns The name of the subcommand relevant to this event.
145 146 147 |
# File 'lib/discordrb/events/interactions.rb', line 145 def subcommand @subcommand end |
#subcommand_group ⇒ String? (readonly)
Returns The name of the subcommand group relevant to this event.
142 143 144 |
# File 'lib/discordrb/events/interactions.rb', line 142 def subcommand_group @subcommand_group end |
#target_id ⇒ Integer? (readonly)
Returns The target of this command when it is a context command.
154 155 156 |
# File 'lib/discordrb/events/interactions.rb', line 154 def target_id @target_id end |
Instance Method Details
#options_attachment(name) ⇒ Attachment
229 230 231 |
# File 'lib/discordrb/events/interactions.rb', line 229 def (name) @resolved[:attachments][@options[name].to_i] end |
#options_channel(name) ⇒ Channel
217 218 219 |
# File 'lib/discordrb/events/interactions.rb', line 217 def (name) @resolved[:channels][@options[name].to_i] end |
#options_member(name) ⇒ Member
205 206 207 |
# File 'lib/discordrb/events/interactions.rb', line 205 def (name) @resolved[:members][@options[name].to_i] end |
#options_mentionable(name) ⇒ Member, Role
223 224 225 |
# File 'lib/discordrb/events/interactions.rb', line 223 def (name) member(name) || role(name) end |
#options_role(name) ⇒ Role
211 212 213 |
# File 'lib/discordrb/events/interactions.rb', line 211 def (name) @resolved[:roles][@options[name].to_i] end |
#options_user(name) ⇒ User
199 200 201 |
# File 'lib/discordrb/events/interactions.rb', line 199 def (name) @resolved[:users][@options[name].to_i] end |
#target ⇒ Message, ...
Returns The target of this command, for context commands.
191 192 193 194 195 |
# File 'lib/discordrb/events/interactions.rb', line 191 def target return nil unless @target_id @resolved.find { |data| data.key?(@target_id) }[@target_id] end |