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.



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

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.



84
85
86
# File 'lib/discordrb/events/interactions.rb', line 84

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.



79
80
81
# File 'lib/discordrb/events/interactions.rb', line 79

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

#delete_responseObject

Delete the original interaction response.



64
65
66
# File 'lib/discordrb/events/interactions.rb', line 64

def delete_response
  @interaction.delete_response
end

#edit_message(message, content: nil, embeds: nil, allowed_mentions: 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.

Yield Parameters:

  • builder (Webhooks::Builder)

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



74
75
76
# File 'lib/discordrb/events/interactions.rb', line 74

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

#edit_response(content: nil, embeds: nil, allowed_mentions: nil, components: 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.

Yield Parameters:

  • builder (Webhooks::Builder)

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

Returns:

  • (InteractionMessage)

    The updated response message.



59
60
61
# File 'lib/discordrb/events/interactions.rb', line 59

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

#respond(content: nil, tts: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: nil, wait: false, components: 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

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
# 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, &block)
  @interaction.respond(
    content: content, tts: tts, embeds: embeds, allowed_mentions: allowed_mentions,
    flags: flags, ephemeral: ephemeral, wait: wait, components: components, &block
  )
end

#send_message(content: nil, embeds: nil, tts: false, allowed_mentions: nil, flags: 0, ephemeral: nil, components: 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.

Yield Parameters:

  • builder (Webhooks::Builder)

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



69
70
71
# File 'lib/discordrb/events/interactions.rb', line 69

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

#update_message(content: nil, tts: nil, embeds: nil, allowed_mentions: nil, flags: 0, ephemeral: nil, wait: false, components: 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

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.



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

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