Class: RubyCord::Interaction
- Inherits:
-
DiscordModel
- Object
- DiscordModel
- RubyCord::Interaction
- Defined in:
- lib/rubycord/interaction.rb,
lib/rubycord/interaction/modal.rb,
lib/rubycord/interaction/command.rb,
lib/rubycord/interaction/response.rb,
lib/rubycord/interaction/components.rb,
lib/rubycord/interaction/autocomplete.rb,
lib/rubycord/interaction/component/button.rb,
lib/rubycord/interaction/command/user_command.rb,
lib/rubycord/interaction/command/slash_command.rb,
lib/rubycord/interaction/component/select_menu.rb,
lib/rubycord/interaction/command/message_command.rb
Overview
Represents a message context menu interaction.
Direct Known Subclasses
Defined Under Namespace
Modules: ModalResponder, SourceResponder, UpdateResponder Classes: AutoComplete, Button, CallbackMessage, Command, Component, MessageCommand, Modal, SelectMenu, SlashCommand, UserCommand
Instance Attribute Summary collapse
-
#app_permissions ⇒ RubyCord::Permission
readonly
The permissions of the bot.
-
#application_id ⇒ RubyCord::Snowflake
readonly
The ID of the application that created the interaction.
-
#guild_locale ⇒ Symbol
readonly
The locale of the guild that created the interaction.
-
#id ⇒ RubyCord::Snowflake
readonly
The ID of the interaction.
-
#locale ⇒ Symbol
readonly
The locale of the user that created the interaction.
-
#token ⇒ String
readonly
The token for the interaction.
-
#type ⇒ Symbol
readonly
The type of interaction.
-
#user ⇒ RubyCord::User, RubyCord::Guild::Member
(also: #member)
readonly
The user or member that created the interaction.
-
#version ⇒ Integer
readonly
The type of interaction.
Instance Method Summary collapse
- #channel ⇒ RubyCord::Channel
-
#delete_original_message ⇒ Async::Task<void>
Delete the original response message.
-
#edit_original_message(content = nil, embed: nil, embeds: nil, attachments: nil, components: nil) ⇒ Async::Task<void>
Edit the original response message.
- #guild ⇒ RubyCord::Guild
-
#inspect ⇒ String
Object class and attributes.
-
#post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, attachment: nil, attachments: nil, components: nil, ephemeral: false) ⇒ RubyCord::Guild::Webhook::Message
Send followup message.
Methods inherited from DiscordModel
Instance Attribute Details
#app_permissions ⇒ RubyCord::Permission (readonly)
Returns The permissions of the bot.
29 30 31 |
# File 'lib/rubycord/interaction.rb', line 29 def @app_permissions end |
#application_id ⇒ RubyCord::Snowflake (readonly)
Returns The ID of the application that created the interaction.
11 12 13 |
# File 'lib/rubycord/interaction.rb', line 11 def application_id @application_id end |
#guild_locale ⇒ Symbol (readonly)
This modifies the language code, -
will be replaced with _
.
Returns The locale of the guild that created the interaction.
27 28 29 |
# File 'lib/rubycord/interaction.rb', line 27 def guild_locale @guild_locale end |
#id ⇒ RubyCord::Snowflake (readonly)
Returns The ID of the interaction.
9 10 11 |
# File 'lib/rubycord/interaction.rb', line 9 def id @id end |
#locale ⇒ Symbol (readonly)
This modifies the language code, -
will be replaced with _
.
Returns The locale of the user that created the interaction.
24 25 26 |
# File 'lib/rubycord/interaction.rb', line 24 def locale @locale end |
#token ⇒ String (readonly)
Returns The token for the interaction.
21 22 23 |
# File 'lib/rubycord/interaction.rb', line 21 def token @token end |
#type ⇒ Symbol (readonly)
Returns The type of interaction.
13 14 15 |
# File 'lib/rubycord/interaction.rb', line 13 def type @type end |
#user ⇒ RubyCord::User, RubyCord::Guild::Member (readonly) Also known as: member
Returns The user or member that created the interaction.
15 16 17 |
# File 'lib/rubycord/interaction.rb', line 15 def user @user end |
#version ⇒ Integer (readonly)
This is always 1
for now.
Returns The type of interaction.
19 20 21 |
# File 'lib/rubycord/interaction.rb', line 19 def version @version end |
Instance Method Details
#channel ⇒ RubyCord::Channel
83 84 85 |
# File 'lib/rubycord/interaction.rb', line 83 def channel @client.channels[@channel_id] end |
#delete_original_message ⇒ Async::Task<void>
Delete the original response message. This method is low-level.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/rubycord/interaction.rb', line 218 def Async do @client .http .request( RubyCord::Internal::Route.new( "/webhooks/#{@application_id}/#{@token}/messages/@original", "//webhooks/:webhook_id/:token/messages/@original", :delete ) ) .wait end end |
#edit_original_message(content = nil, embed: nil, embeds: nil, attachments: nil, components: nil) ⇒ Async::Task<void>
Edit the original response message. This method is low-level.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/rubycord/interaction.rb', line 174 def ( content = nil, embed: nil, embeds: nil, attachments: nil, components: nil ) Async do payload = {} payload[:content] = content if content payload[:embeds] = ( || []) .map { |e| e&.to_hash } .filter { _1 } .then { _1.empty? ? nil : _1 } payload[:components] = Component.to_payload(components) if components payload[:attachments] = .map.with_index do |a, i| { id: i, filename: a.filename, description: a.description } end if payload.compact! @client .http .multipart_request( RubyCord::Internal::Route.new( "/webhooks/#{@application_id}/#{@token}/messages/@original", "//webhooks/:webhook_id/:token/messages/@original", :patch ), payload, ) .wait end end |
#guild ⇒ RubyCord::Guild
78 79 80 |
# File 'lib/rubycord/interaction.rb', line 78 def guild @client.guilds[@guild_id] end |
#inspect ⇒ String
Returns Object class and attributes.
88 89 90 |
# File 'lib/rubycord/interaction.rb', line 88 def inspect "#<#{self.class} id=#{@id}>" end |
#post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, attachment: nil, attachments: nil, components: nil, ephemeral: false) ⇒ RubyCord::Guild::Webhook::Message
Send followup message.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/rubycord/interaction.rb', line 109 def post( content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, attachment: nil, attachments: nil, components: nil, ephemeral: false ) Async do payload = {} payload[:content] = content if content payload[:tts] = tts payload[:embeds] = ( || []) .map { |e| e&.to_hash } .filter { _1 } payload[:allowed_mentions] = allowed_mentions&.to_hash( @client.allowed_mentions ) || @client.allowed_mentions.to_hash payload[:components] = Component.to_payload(components) if components payload[:flags] = (ephemeral ? 1 << 6 : 0) ||= ? [] : [] payload[:attachments] = .map.with_index do |a, i| { id: i, filename: a.filename, description: a.description } end _resp, data = @client .http .multipart_request( RubyCord::Internal::Route.new( "/webhooks/#{@application_id}/#{@token}", "//webhooks/:webhook_id/:token", :post ), payload, ) .wait webhook = Guild::Webhook::URLWebhook.new("/webhooks/#{@application_id}/#{@token}") Guild::Webhook::Message.new(webhook, data, @client) ret end end |