Class: Discorb::Interaction
- Inherits:
-
DiscordModel
- Object
- DiscordModel
- Discorb::Interaction
- Defined in:
- lib/discorb/interaction/root.rb,
lib/discorb/interaction/response.rb
Overview
Represents an interaction of Discord.
Direct Known Subclasses
AutoComplete, CommandInteraction, MessageComponentInteraction, ModalInteraction
Defined Under Namespace
Modules: ModalResponder, SourceResponder, UpdateResponder Classes: CallbackMessage
Instance Attribute Summary collapse
-
#app_permissions -> Discorb::Permission
readonly
The permissions of the bot.
-
#application_id -> Discorb::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 -> Discorb::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 -> Discorb::User, Discorb::Member
(also: #member)
readonly
The user or member that created the interaction.
-
#version -> Integer
readonly
The type of interaction.
Instance Method Summary collapse
- #channel -> Object
-
#delete_original_message -> Async::Task<void>
Delete the original response message.
-
#edit_original_message(content = nil, embed: nil, embeds: nil, attachment: nil, attachments: nil, components: nil) -> Async::Task<void>
Edit the original response message.
- #guild -> Object
- #inspect -> Object
-
#post(content = nil, tts: false, embed: nil, embeds: nil, allowed_mentions: nil, attachment: nil, attachments: nil, components: nil, ephemeral: false) -> Discorb::Webhook::Message
Send followup message.
Methods inherited from DiscordModel
Instance Attribute Details
#app_permissions -> Discorb::Permission (readonly)
Returns The permissions of the bot.
29 30 31 |
# File 'lib/discorb/interaction/root.rb', line 29 def @app_permissions end |
#application_id -> Discorb::Snowflake (readonly)
Returns The ID of the application that created the interaction.
11 12 13 |
# File 'lib/discorb/interaction/root.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/discorb/interaction/root.rb', line 27 def guild_locale @guild_locale end |
#id -> Discorb::Snowflake (readonly)
Returns The ID of the interaction.
9 10 11 |
# File 'lib/discorb/interaction/root.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/discorb/interaction/root.rb', line 24 def locale @locale end |
#token -> String (readonly)
Returns The token for the interaction.
21 22 23 |
# File 'lib/discorb/interaction/root.rb', line 21 def token @token end |
#type -> Symbol (readonly)
Returns The type of interaction.
13 14 15 |
# File 'lib/discorb/interaction/root.rb', line 13 def type @type end |
#user -> Discorb::User, Discorb::Member (readonly) Also known as: member
Returns The user or member that created the interaction.
15 16 17 |
# File 'lib/discorb/interaction/root.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/discorb/interaction/root.rb', line 19 def version @version end |
Instance Method Details
#channel -> Object
81 82 83 |
# File 'lib/discorb/interaction/root.rb', line 81 def channel @client.channels[@channel_id] end |
#delete_original_message -> Async::Task<void>
Delete the original response message. This method is low-level.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/discorb/interaction/root.rb', line 219 def Async do @client .http .request( 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, attachment: nil, attachments: nil, components: nil) -> Async::Task<void>
Edit the original response message. This method is low-level.
173 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 209 |
# File 'lib/discorb/interaction/root.rb', line 173 def ( content = nil, embed: nil, embeds: nil, attachment: 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 payload.compact! @client .http .multipart_request( Route.new( "/webhooks/#{@application_id}/#{@token}/messages/@original", "//webhooks/:webhook_id/:token/messages/@original", :patch ), payload, ) .wait end end |
#guild -> Object
77 78 79 |
# File 'lib/discorb/interaction/root.rb', line 77 def guild @client.guilds[@guild_id] end |
#inspect -> Object
85 86 87 |
# File 'lib/discorb/interaction/root.rb', line 85 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) -> Discorb::Webhook::Message
Send followup message.
106 107 108 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 |
# File 'lib/discorb/interaction/root.rb', line 106 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( Route.new( "/webhooks/#{@application_id}/#{@token}", "//webhooks/:webhook_id/:token", :post ), payload, ) .wait webhook = Webhook::URLWebhook.new("/webhooks/#{@application_id}/#{@token}") Webhook::Message.new(webhook, data, @client) ret end end |