Class: Discordrb::Events::InteractionCreateEvent

Inherits:
Event
  • Object
show all
Defined in:
lib/discordrb/events/interactions.rb

Overview

Generic subclass for interaction events

Direct Known Subclasses

ApplicationCommandEvent, ComponentEvent

Instance Attribute Summary collapse

Attributes inherited from Event

#bot

Instance Method Summary collapse

Constructor Details

#initialize(data, bot) ⇒ InteractionCreateEvent

Returns a new instance of InteractionCreateEvent.



32
33
34
35
# File 'lib/discordrb/events/interactions.rb', line 32

def initialize(data, bot)
  @interaction = Discordrb::Interaction.new(data, bot)
  @bot = bot
end

Instance Attribute Details

#channelChannel (readonly)

Returns:

See Also:



30
# File 'lib/discordrb/events/interactions.rb', line 30

delegate :type, :server, :server_id, :channel, :channel_id, :user, to: :interaction

#channel_idInteger (readonly)

Returns:

See Also:



30
# File 'lib/discordrb/events/interactions.rb', line 30

delegate :type, :server, :server_id, :channel, :channel_id, :user, to: :interaction

#interactionInteraction (readonly)

Returns The interaction for this event.

Returns:



10
11
12
# File 'lib/discordrb/events/interactions.rb', line 10

def interaction
  @interaction
end

#serverServer? (readonly)

Returns:

See Also:



30
# File 'lib/discordrb/events/interactions.rb', line 30

delegate :type, :server, :server_id, :channel, :channel_id, :user, to: :interaction

#server_idInteger (readonly)

Returns:

See Also:



30
# File 'lib/discordrb/events/interactions.rb', line 30

delegate :type, :server, :server_id, :channel, :channel_id, :user, to: :interaction

#typeInteger (readonly)

Returns:

See Also:



30
# File 'lib/discordrb/events/interactions.rb', line 30

delegate :type, :server, :server_id, :channel, :channel_id, :user, to: :interaction

#userUser (readonly)

Returns:

See Also:



30
# File 'lib/discordrb/events/interactions.rb', line 30

delegate :type, :server, :server_id, :channel, :channel_id, :user, to: :interaction

Instance Method Details

#defer(flags: 0, ephemeral: true) ⇒ Object

Defer an interaction, setting a temporary response that can be later overriden by Interaction#send_message. This method is used when you want to use a single message for your response but require additional processing time, or to simply ack an interaction so an error is not displayed.

Parameters:

  • flags (Integer) (defaults to: 0)

    Message flags.

  • ephemeral (true, false) (defaults to: true)

    Whether this message should only be visible to the interaction initiator.



47
48
49
# File 'lib/discordrb/events/interactions.rb', line 47

def defer(flags: 0, ephemeral: true)
  @interaction.defer(flags: flags, ephemeral: ephemeral)
end

#defer_updateObject

Defer an update to an interaction. This is can only currently used by Button interactions.



91
92
93
# File 'lib/discordrb/events/interactions.rb', line 91

def defer_update
  @interaction.defer_update
end

#delete_message(message) ⇒ Object

Parameters:

  • message (Integer, String, InteractionMessage, Message)

    The message created by this interaction to be deleted.



86
87
88
# File 'lib/discordrb/events/interactions.rb', line 86

def delete_message(message)
  @interaction.delete_message(message)
end

#delete_responseObject

Delete the original interaction response.



71
72
73
# File 'lib/discordrb/events/interactions.rb', line 71

def delete_response
  @interaction.delete_response
end

#edit_message(message, content: nil, embeds: nil, allowed_mentions: nil, attachments: nil) {|builder| ... } ⇒ Object

Parameters:

  • message (String, Integer, InteractionMessage, Message)

    The message created by this interaction to be edited.

  • content (String) (defaults to: nil)

    The message content.

  • embeds (Array<Hash, Webhooks::Embed>) (defaults to: nil)

    The embeds for the message.

  • allowed_mentions (Hash, AllowedMentions) (defaults to: nil)

    Mentions that can ping on this message.

  • attachments (Array<File>) (defaults to: nil)

    Files that can be referenced in embeds via attachment://file.png.

Yield Parameters:

  • builder (Webhooks::Builder)

    An optional message builder. Arguments passed to the method overwrite builder data.



81
82
83
# File 'lib/discordrb/events/interactions.rb', line 81

def edit_message(message, content: nil, embeds: nil, allowed_mentions: nil, attachments: nil, &block)
  @interaction.edit_message(message, content: content, embeds: embeds, allowed_mentions: allowed_mentions, attachments: attachments, &block)
end

#edit_response(content: nil, embeds: nil, allowed_mentions: nil, components: nil, attachments: nil) {|builder| ... } ⇒ InteractionMessage

Edit the original response to this interaction.

Parameters:

  • content (String) (defaults to: nil)

    The content of the message.

  • embeds (Array<Hash, Webhooks::Embed>) (defaults to: nil)

    The embeds for the message.

  • allowed_mentions (Hash, AllowedMentions) (defaults to: nil)

    Mentions that can ping on this message.

  • components (Array<#to_h>) (defaults to: nil)

    An array of components.

  • attachments (Array<File>) (defaults to: nil)

    Files that can be referenced in embeds via attachment://file.png.

Yield Parameters:

  • builder (Webhooks::Builder)

    An optional message builder. Arguments passed to the method overwrite builder data.

Returns:

  • (InteractionMessage)

    The updated response message.



66
67
68
# File 'lib/discordrb/events/interactions.rb', line 66

def edit_response(content: nil, embeds: nil, allowed_mentions: nil, components: nil, attachments: nil, &block)
  @interaction.edit_response(content: content, embeds: embeds, allowed_mentions: allowed_mentions, components: components, attachments: attachments, &block)
end

#get_component(custom_id) ⇒ TextInput, ...

Returns:

  • (TextInput, Button, SelectMenu)


96
97
98
# File 'lib/discordrb/events/interactions.rb', line 96

def get_component(custom_id)
  @interaction.get_component(custom_id)
end

#respond(content: nil, tts: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: nil, wait: false, components: nil, attachments: nil) {|builder, view| ... } ⇒ Object

Respond to the creation of this interaction. An interaction must be responded to or deferred, The response may be modified with Interaction#edit_response or deleted with Interaction#delete_response. Further messages can be sent with Interaction#send_message.

Parameters:

  • content (String) (defaults to: nil)

    The content of the message.

  • tts (true, false) (defaults to: nil)
  • embeds (Array<Hash, Webhooks::Embed>) (defaults to: nil)

    The embeds for the message.

  • allowed_mentions (Hash, AllowedMentions) (defaults to: nil)

    Mentions that can ping on this message.

  • flags (Integer) (defaults to: 0)

    Message flags.

  • ephemeral (true, false) (defaults to: nil)

    Whether this message should only be visible to the interaction initiator.

  • wait (true, false) (defaults to: false)

    Whether this method should return a Message object of the interaction response.

  • components (Array<#to_h>) (defaults to: nil)

    An array of components.

  • attachments (Array<File>) (defaults to: nil)

    Files that can be referenced in embeds via attachment://file.png.

Yield Parameters:

  • builder (Webhooks::Builder)

    An optional message builder. Arguments passed to the method overwrite builder data.

  • view (Webhooks::View)

    A builder for creating interaction components.



38
39
40
41
42
43
44
# File 'lib/discordrb/events/interactions.rb', line 38

def respond(content: nil, tts: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: nil, wait: false, components: nil, attachments: nil, &block)
  @interaction.respond(
    content: content, tts: tts, embeds: embeds, allowed_mentions: allowed_mentions,
    flags: flags, ephemeral: ephemeral, wait: wait, components: components, attachments: attachments,
    &block
  )
end

#send_message(content: nil, embeds: nil, tts: false, allowed_mentions: nil, flags: 0, ephemeral: nil, components: nil, attachments: nil) {|builder| ... } ⇒ Object

Parameters:

  • content (String) (defaults to: nil)

    The content of the message.

  • tts (true, false) (defaults to: false)
  • embeds (Array<Hash, Webhooks::Embed>) (defaults to: nil)

    The embeds for the message.

  • allowed_mentions (Hash, AllowedMentions) (defaults to: nil)

    Mentions that can ping on this message.

  • flags (Integer) (defaults to: 0)

    Message flags.

  • ephemeral (true, false) (defaults to: nil)

    Whether this message should only be visible to the interaction initiator.

  • attachments (Array<File>) (defaults to: nil)

    Files that can be referenced in embeds via attachment://file.png.

Yield Parameters:

  • builder (Webhooks::Builder)

    An optional message builder. Arguments passed to the method overwrite builder data.



76
77
78
# File 'lib/discordrb/events/interactions.rb', line 76

def send_message(content: nil, embeds: nil, tts: false, allowed_mentions: nil, flags: 0, ephemeral: nil, components: nil, attachments: nil, &block)
  @interaction.send_message(content: content, embeds: embeds, tts: tts, allowed_mentions: allowed_mentions, flags: flags, ephemeral: ephemeral, components: components, attachments: attachments, &block)
end

#show_modal(title:, custom_id:, components: nil) {|A| ... } ⇒ Object

Create a modal as a response.

Parameters:

  • title (String)

    The title of the modal being shown.

  • custom_id (String)

    The custom_id used to identify the modal and store data.

  • components (Array<Component, Hash>, nil) (defaults to: nil)

    An array of components. These can be defined through the block as well.

Yield Parameters:



61
62
63
# File 'lib/discordrb/events/interactions.rb', line 61

def show_modal(title:, custom_id:, components: nil, &block)
  @interaction.show_modal(title: title, custom_id: custom_id, components: components, &block)
end

#update_message(content: nil, tts: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: nil, wait: false, components: nil, attachments: nil) {|builder, view| ... } ⇒ Object

Respond to the creation of this interaction. An interaction must be responded to or deferred, The response may be modified with Interaction#edit_response or deleted with Interaction#delete_response. Further messages can be sent with Interaction#send_message.

Parameters:

  • content (String) (defaults to: nil)

    The content of the message.

  • tts (true, false) (defaults to: nil)
  • embeds (Array<Hash, Webhooks::Embed>) (defaults to: nil)

    The embeds for the message.

  • allowed_mentions (Hash, AllowedMentions) (defaults to: nil)

    Mentions that can ping on this message.

  • flags (Integer) (defaults to: 0)

    Message flags.

  • ephemeral (true, false) (defaults to: nil)

    Whether this message should only be visible to the interaction initiator.

  • wait (true, false) (defaults to: false)

    Whether this method should return a Message object of the interaction response.

  • components (Array<#to_h>) (defaults to: nil)

    An array of components.

  • attachments (Array<File>) (defaults to: nil)

    Files that can be referenced in embeds via attachment://file.png.

Yield Parameters:

  • builder (Webhooks::Builder)

    An optional message builder. Arguments passed to the method overwrite builder data.

  • view (Webhooks::View)

    A builder for creating interaction components.



52
53
54
55
56
57
58
# File 'lib/discordrb/events/interactions.rb', line 52

def update_message(content: nil, tts: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: nil, wait: false, components: nil, attachments: nil, &block)
  @interaction.update_message(
    content: content, tts: tts, embeds: embeds, allowed_mentions: allowed_mentions,
    flags: flags, ephemeral: ephemeral, wait: wait, components: components, attachments: attachments,
    &block
  )
end