Module: Discordrb::EventContainer

Includes:
Events
Included in:
Bot
Defined in:
lib/discordrb/container.rb

Overview

This module provides the functionality required for events and awaits. It is separated from the Bot class so users can make their own container modules and include them.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Events

#added_members, matches_all

Class Method Details

.class_from_string(str) ⇒ Class

Utility method to return a class object from a string of its name. Mostly useful for internal stuff

Parameters:

  • str (String)

    The name of the class

Returns:

  • (Class)

    the class



794
795
796
797
798
# File 'lib/discordrb/container.rb', line 794

def self.class_from_string(str)
  str.split('::').inject(Object) do |mod, class_name|
    mod.const_get(class_name)
  end
end

.event_class(handler_class) ⇒ Class?

Returns the event class for a handler class type

Parameters:

  • handler_class (Class)

    The handler type

Returns:

  • (Class, nil)

    the event type, or nil if the handler_class isn't a handler class (i.e. ends with Handler)

See Also:

  • #handler_class


784
785
786
787
788
789
# File 'lib/discordrb/container.rb', line 784

def self.event_class(handler_class)
  class_name = handler_class.to_s
  return nil unless class_name.end_with? 'Handler'

  EventContainer.class_from_string(class_name[0..-8])
end

.handler_class(event_class) ⇒ Class

Returns the handler class for an event class type

Parameters:

  • event_class (Class)

    The event type

Returns:

  • (Class)

    the handler type

See Also:

  • #event_class


776
777
778
# File 'lib/discordrb/container.rb', line 776

def self.handler_class(event_class)
  class_from_string("#{event_class}Handler")
end

Instance Method Details

#add_handler(handler) ⇒ Object Also known as: <<

Adds an event handler to this container. Usually, it's more expressive to just use one of the shorthand adder methods like #message, but if you want to create one manually you can use this.

Parameters:



744
745
746
747
748
749
# File 'lib/discordrb/container.rb', line 744

def add_handler(handler)
  clazz = EventContainer.event_class(handler.class)
  @event_handlers ||= {}
  @event_handlers[clazz] ||= []
  @event_handlers[clazz] << handler
end

#application_command(name, attributes = {}) {|event| ... } ⇒ ApplicationCommandEventHandler

This event is raised whenever an application command (slash command) is executed.

Parameters:

  • name (Symbol)

    The name of the application command this handler is for.

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



569
570
571
572
573
574
575
576
577
578
# File 'lib/discordrb/container.rb', line 569

def application_command(name, attributes = {}, &block)
  @application_commands ||= {}

  unless block
    @application_commands[name] ||= ApplicationCommandEventHandler.new(attributes, nil)
    return @application_commands[name]
  end

  @application_commands[name] = ApplicationCommandEventHandler.new(attributes, block)
end

#application_command_permissions_update(attributes = {}) {|event| ... } ⇒ ApplicationCommandPermissionsUpdateEventHandler

This event is raised whenever an application command's permissions are updated.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



695
696
697
# File 'lib/discordrb/container.rb', line 695

def application_command_permissions_update(attributes = {}, &block)
  register_event(ApplicationCommandPermissionsUpdateEvent, attributes, block)
end

#autocomplete(name = nil, attributes = {}) {|event| ... } ⇒ AutocompleteEventHandler

This event is raised whenever an autocomplete interaction is created.

Parameters:

  • name (String, Symbol, nil) (defaults to: nil)

    An option name to match against.

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :command_id (String, Integer)

    A command ID to match against.

  • :subcommand (String, Symbol)

    A subcommand name to match against.

  • :subcommand_group (String, Symbol)

    A subcommand group to match against.

  • :command_name (String, Symbol)

    A command name to match against.

  • :server (String, Integer, Server)

    A server to match against.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



683
684
685
# File 'lib/discordrb/container.rb', line 683

def autocomplete(name = nil, attributes = {}, &block)
  register_event(AutocompleteEvent, attributes.merge!({ name: name }), block)
end

#await(attributes = {}) {|event| ... } ⇒ AwaitEventHandler

This event is raised when an Await is triggered. It provides an easy way to execute code on an await without having to rely on the await's block.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :key (Symbol)

    Exactly matches the await's key.

  • :type (Class)

    Exactly matches the event's type.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

  • event (AwaitEvent)

    The event that was raised.

Returns:



499
500
501
# File 'lib/discordrb/container.rb', line 499

def await(attributes = {}, &block)
  register_event(AwaitEvent, attributes, block)
end

#button(attributes = {}) {|event| ... } ⇒ ButtonEventHandler

This event is raised whenever an button interaction is created.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :custom_id (String, Regexp)

    A custom_id to match against.

  • :message (String, Integer, Message)

    The message to filter for.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



587
588
589
# File 'lib/discordrb/container.rb', line 587

def button(attributes = {}, &block)
  register_event(ButtonEvent, attributes, block)
end

#channel_create(attributes = {}) {|event| ... } ⇒ ChannelCreateEventHandler

This event is raised when a channel is created.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :type (Integer)

    Matches the type of channel that is being created (0: text, 1: private, 2: voice, 3: group)

  • :name (String)

    Matches the name of the created channel.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



240
241
242
# File 'lib/discordrb/container.rb', line 240

def channel_create(attributes = {}, &block)
  register_event(ChannelCreateEvent, attributes, block)
end

#channel_delete(attributes = {}) {|event| ... } ⇒ ChannelDeleteEventHandler

This event is raised when a channel is deleted.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :type (Integer)

    Matches the type of channel that is being deleted (0: text, 1: private, 2: voice, 3: group).

  • :name (String)

    Matches the name of the deleted channel.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



262
263
264
# File 'lib/discordrb/container.rb', line 262

def channel_delete(attributes = {}, &block)
  register_event(ChannelDeleteEvent, attributes, block)
end

#channel_pins_update(attributes = {}) {|event| ... } ⇒ ChannelPinsUpdateEventHandler

This event is raised whenever a message is pinned or unpinned.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



668
669
670
# File 'lib/discordrb/container.rb', line 668

def channel_pins_update(attributes = {}, &block)
  register_event(ChannelPinsUpdateEvent, attributes, block)
end

#channel_recipient_add(attributes = {}) {|event| ... } ⇒ ChannelRecipientAddHandler

This event is raised when a recipient is added to a group channel.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :name (String)

    Matches the name of the group channel that the recipient is added to.

  • :owner_id (String, Integer)

    Matches the ID of the group channel's owner.

  • :id (String, Integer)

    Matches the ID of the recipient added to the group channel.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:

  • (ChannelRecipientAddHandler)

    the event handler that was registered.



274
275
276
# File 'lib/discordrb/container.rb', line 274

def channel_recipient_add(attributes = {}, &block)
  register_event(ChannelRecipientAddEvent, attributes, block)
end

#channel_recipient_remove(attributes = {}) {|event| ... } ⇒ ChannelRecipientRemoveHandler

This event is raised when a recipient is removed from a group channel.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :name (String)

    Matches the name of the group channel that the recipient is added to.

  • :owner_id (String, Integer)

    Matches the ID of the group channel's owner.

  • :id (String, Integer)

    Matches the ID of the recipient removed from the group channel.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:

  • (ChannelRecipientRemoveHandler)

    the event handler that was registered.



286
287
288
# File 'lib/discordrb/container.rb', line 286

def channel_recipient_remove(attributes = {}, &block)
  register_event(ChannelRecipientRemoveEvent, attributes, block)
end

#channel_select(attributes = {}) {|event| ... } ⇒ ChannelSelectEventHandler

This event is raised whenever an select channel interaction is created.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :custom_id (String, Regexp)

    A custom_id to match against.

  • :message (String, Integer, Message)

    The message to filter for.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



657
658
659
# File 'lib/discordrb/container.rb', line 657

def channel_select(attributes = {}, &block)
  register_event(ChannelSelectEvent, attributes, block)
end

#channel_update(attributes = {}) {|event| ... } ⇒ ChannelUpdateEventHandler

This event is raised when a channel is updated.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :type (Integer)

    Matches the type of channel that is being updated (0: text, 1: private, 2: voice, 3: group).

  • :name (String)

    Matches the new name of the channel.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



251
252
253
# File 'lib/discordrb/container.rb', line 251

def channel_update(attributes = {}, &block)
  register_event(ChannelUpdateEvent, attributes, block)
end

#clear!Object

Removes all events from this event handler.



736
737
738
739
# File 'lib/discordrb/container.rb', line 736

def clear!
  @event_handlers&.clear
  @application_commands&.clear
end

#disconnected(attributes = {}) {|event| ... } ⇒ DisconnectEventHandler

This event is raised when the bot has disconnected from the WebSocket, due to the Bot#stop method or external causes. It's the recommended way to do clean-up tasks.

Parameters:

  • attributes (Hash) (defaults to: {})

    Event attributes, none in this particular case

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



60
61
62
# File 'lib/discordrb/container.rb', line 60

def disconnected(attributes = {}, &block)
  register_event(DisconnectEvent, attributes, block)
end

#heartbeat(attributes = {}) {|event| ... } ⇒ HeartbeatEventHandler

This event is raised every time the bot sends a heartbeat over the galaxy. This happens roughly every 40 seconds, but may happen at a lower rate should Discord change their interval. It may also happen more quickly for periods of time, especially for unstable connections, since discordrb rather sends a heartbeat than not if there's a choice. (You shouldn't rely on all this to be accurately timed.)

All this makes this event useful to periodically trigger something, like doing some API request every hour, setting some kind of uptime variable or whatever else. The only limit is yourself.

Parameters:

  • attributes (Hash) (defaults to: {})

    Event attributes, none in this particular case

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



75
76
77
# File 'lib/discordrb/container.rb', line 75

def heartbeat(attributes = {}, &block)
  register_event(HeartbeatEvent, attributes, block)
end

#include_events(container) ⇒ Object Also known as: include!

Adds all event handlers from another container into this one. Existing event handlers will be overwritten.

Parameters:



753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
# File 'lib/discordrb/container.rb', line 753

def include_events(container)
  application_command_handlers = container.instance_variable_get(:@application_commands)
  handlers = container.instance_variable_get :@event_handlers
  return unless handlers || application_command_handlers

  @event_handlers ||= {}
  @event_handlers.merge!(handlers || {}) { |_, old, new| old + new }

  @application_commands ||= {}

  @application_commands.merge!(application_command_handlers || {}) do |_, old, new|
    old.subcommands.merge!(new.subcommands)
    old
  end
end

#interaction_create(attributes = {}) {|event| ... } ⇒ InteractionCreateEventHandler

This event is raised whenever an interaction event is received.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



559
560
561
# File 'lib/discordrb/container.rb', line 559

def interaction_create(attributes = {}, &block)
  register_event(InteractionCreateEvent, attributes, block)
end

#invite_create(attributes = {}) {|event| ... } ⇒ InviteCreateEventHandler

This event is raised when an invite is created.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :inviter (String, Integer, User)

    Matches the user that created the invite.

  • :channel (String, Integer, Channel)

    Matches the channel the invite was created for.

  • :server (String, Integer, Server)

    Matches the server the invite was created for.

  • :temporary (true, false)

    Matches whether the invite is temporary or not.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



534
535
536
# File 'lib/discordrb/container.rb', line 534

def invite_create(attributes = {}, &block)
  register_event(InviteCreateEvent, attributes, block)
end

#invite_delete(attributes = {}) {|event| ... } ⇒ InviteDeleteEventHandler

This event is raised when an invite is deleted.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised

Yield Parameters:

Returns:



545
546
547
# File 'lib/discordrb/container.rb', line 545

def invite_delete(attributes = {}, &block)
  register_event(InviteDeleteEvent, attributes, block)
end

#member_join(attributes = {}) {|event| ... } ⇒ ServerMemberAddEventHandler

This event is raised when a new user joins a server.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :username (String)

    Matches the username of the joined user.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



323
324
325
# File 'lib/discordrb/container.rb', line 323

def member_join(attributes = {}, &block)
  register_event(ServerMemberAddEvent, attributes, block)
end

#member_leave(attributes = {}) {|event| ... } ⇒ ServerMemberDeleteEventHandler

This event is raised when a member leaves a server.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :username (String)

    Matches the username of the member.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



344
345
346
# File 'lib/discordrb/container.rb', line 344

def member_leave(attributes = {}, &block)
  register_event(ServerMemberDeleteEvent, attributes, block)
end

#member_update(attributes = {}) {|event| ... } ⇒ ServerMemberUpdateEventHandler

This event is raised when a member update happens. This includes when a members nickname or roles are updated.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :username (String)

    Matches the username of the updated user.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



334
335
336
# File 'lib/discordrb/container.rb', line 334

def member_update(attributes = {}, &block)
  register_event(ServerMemberUpdateEvent, attributes, block)
end

#mention(attributes = {}) {|event| ... } ⇒ MentionEventHandler

This event is raised when the bot is mentioned in a message.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :start_with (String, Regexp)

    Matches the string the message starts with.

  • :end_with (String, Regexp)

    Matches the string the message ends with.

  • :contains (String, Regexp)

    Matches a string the message contains.

  • :in (String, Integer, Channel)

    Matches the channel the message was sent in.

  • :from (String, Integer, User)

    Matches the user that sent the message.

  • :content (String)

    Exactly matches the entire content of the message.

  • :after (Time)

    Matches a time after the time the message was sent at.

  • :before (Time)

    Matches a time before the time the message was sent at.

  • :private (Boolean)

    Matches whether or not the channel is private.

  • :type (Integer, String, Symbol)

    Matches the type of the message that was sent.

  • :role_mention (true, false)

    If the event should trigger when the bot's managed role is mentioned.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



229
230
231
# File 'lib/discordrb/container.rb', line 229

def mention(attributes = {}, &block)
  register_event(MentionEvent, attributes, block)
end

#mentionable_select(attributes = {}) {|event| ... } ⇒ MentionableSelectEventHandler

This event is raised whenever an select mentionable interaction is created.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :custom_id (String, Regexp)

    A custom_id to match against.

  • :message (String, Integer, Message)

    The message to filter for.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



646
647
648
# File 'lib/discordrb/container.rb', line 646

def mentionable_select(attributes = {}, &block)
  register_event(MentionableSelectEvent, attributes, block)
end

#message(attributes = {}) {|event| ... } ⇒ MessageEventHandler

This event is raised when a message is sent to a text channel the bot is currently in.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :start_with (String, Regexp)

    Matches the string the message starts with.

  • :end_with (String, Regexp)

    Matches the string the message ends with.

  • :contains (String, Regexp)

    Matches a string the message contains.

  • :in (String, Integer, Channel)

    Matches the channel the message was sent in.

  • :from (String, Integer, User)

    Matches the user that sent the message.

  • :content (String)

    Exactly matches the entire content of the message.

  • :after (Time)

    Matches a time after the time the message was sent at.

  • :before (Time)

    Matches a time before the time the message was sent at.

  • :private (Boolean)

    Matches whether or not the channel is private.

  • :type (Integer, String, Symbol)

    Matches the type of the message that was sent.

  • :server (Server, Integer, String)

    Matches the server the message was sent in.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



40
41
42
# File 'lib/discordrb/container.rb', line 40

def message(attributes = {}, &block)
  register_event(MessageEvent, attributes, block)
end

#message_delete(attributes = {}) {|event| ... } ⇒ MessageDeleteEventHandler

This event is raised when a message is deleted in a channel.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



115
116
117
# File 'lib/discordrb/container.rb', line 115

def message_delete(attributes = {}, &block)
  register_event(MessageDeleteEvent, attributes, block)
end

#message_edit(attributes = {}) {|event| ... } ⇒ MessageEditEventHandler

This event is raised when a message is edited in a channel.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :id (String, Integer)

    Matches the ID of the message that was edited.

  • :in (String, Integer, Channel)

    Matches the channel the message was edited in.

  • :type (Integer, String, Symbol)

    Matches the type of the message that was edited.

  • :server (Server, Integer, String)

    Matches the server the message was edited in.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



103
104
105
# File 'lib/discordrb/container.rb', line 103

def message_edit(attributes = {}, &block)
  register_event(MessageEditEvent, attributes, block)
end

#message_update(attributes = {}) {|event| ... } ⇒ MessageUpdateEventHandler

This event is raised whenever a message is updated. Message updates can be triggered from a user editing their own message, or from Discord automatically attaching embeds to the user's message for URLs contained in the message's content. If you only want to listen for users editing their own messages, use the #message_edit handler instead.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :id (String, Integer)

    Matches the ID of the message that was updated.

  • :in (String, Integer, Channel)

    Matches the channel the message was updated in.

  • :type (Integer, String, Symbol)

    Matches the type of the message that was updated.

  • :server (Server, Integer, String)

    Matches the server the message was updated in.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



131
132
133
# File 'lib/discordrb/container.rb', line 131

def message_update(attributes = {}, &block)
  register_event(MessageUpdateEvent, attributes, block)
end

This event is raised whenever a modal is submitted.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :custom_id (String, Regexp)

    A custom_id to match against.

  • :message (String, Integer, Message)

    The message to filter for.

  • :server (String, Integer, Server, nil)

    The server where this event was created. nil for DM channels.

  • :channel (String, Integer, Channel)

    The channel where this event was created.

  • :user (String, Integer, User)

    The user that triggered this event. # @yield The block is executed when the event is raised.

Yield Parameters:

Returns:



613
614
615
# File 'lib/discordrb/container.rb', line 613

def modal_submit(attributes = {}, &block)
  register_event(ModalSubmitEvent, attributes, block)
end

#playing(attributes = {}) {|event| ... } ⇒ PlayingEventHandler

This event is raised when the game a user is playing changes.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :from (String, Integer, User)

    Matches the user whose playing game changes.

  • :game (String)

    Matches the game the user is now playing.

  • :type (Integer)

    Matches the type of game object (0 game, 1 Twitch stream)

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



209
210
211
# File 'lib/discordrb/container.rb', line 209

def playing(attributes = {}, &block)
  register_event(PlayingEvent, attributes, block)
end

#pm(attributes = {}) {|event| ... } ⇒ PrivateMessageEventHandler Also known as: private_message, direct_message, dm

This event is raised when a private message is sent to the bot.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :start_with (String, Regexp)

    Matches the string the message starts with.

  • :end_with (String, Regexp)

    Matches the string the message ends with.

  • :contains (String, Regexp)

    Matches a string the message contains.

  • :in (String, Integer, Channel)

    Matches the channel the message was sent in.

  • :from (String, Integer, User)

    Matches the user that sent the message.

  • :content (String)

    Exactly matches the entire content of the message.

  • :after (Time)

    Matches a time after the time the message was sent at.

  • :before (Time)

    Matches a time before the time the message was sent at.

  • :private (Boolean)

    Matches whether or not the channel is private.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



517
518
519
# File 'lib/discordrb/container.rb', line 517

def pm(attributes = {}, &block)
  register_event(PrivateMessageEvent, attributes, block)
end

#presence(attributes = {}) {|event| ... } ⇒ PresenceEventHandler

This event is raised when a user's status (online/offline/idle) changes.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :from (String, Integer, User)

    Matches the user whose status changed.

  • :status (:offline, :idle, :online)

    Matches the status the user has now.

  • :client_status (Hash<Symbol, Symbol>)

    Matches the current online status (:online, :idle or :dnd) of the user on various device types (:desktop, :mobile, or :web). The value will be nil when the user is offline or invisible

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



197
198
199
# File 'lib/discordrb/container.rb', line 197

def presence(attributes = {}, &block)
  register_event(PresenceEvent, attributes, block)
end

#raw(attributes = {}) {|event| ... } ⇒ RawEventHandler

This event is raised for every dispatch received over the gateway, whether supported by discordrb or not.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :type (String, Symbol, Regexp)

    Matches the event type of the dispatch.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

  • event (RawEvent)

    The event that was raised.

Returns:



705
706
707
# File 'lib/discordrb/container.rb', line 705

def raw(attributes = {}, &block)
  register_event(RawEvent, attributes, block)
end

#reaction_add(attributes = {}) {|event| ... } ⇒ ReactionAddEventHandler

This event is raised when somebody reacts to a message.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :emoji (String, Integer)

    Matches the ID of the emoji that was reacted with, or its name.

  • :from (String, Integer, User)

    Matches the user who added the reaction.

  • :message (String, Integer, Message)

    Matches the message to which the reaction was added.

  • :in (String, Integer, Channel)

    Matches the channel the reaction was added in.

  • :type (Integer, String, Symbol)

    Matches the type of reaction (:normal or :burst) that was added.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



145
146
147
# File 'lib/discordrb/container.rb', line 145

def reaction_add(attributes = {}, &block)
  register_event(ReactionAddEvent, attributes, block)
end

#reaction_remove(attributes = {}) {|event| ... } ⇒ ReactionRemoveEventHandler

This event is raised when somebody removes a reaction from a message.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :emoji (String, Integer)

    Matches the ID of the emoji that was removed from the reactions, or its name.

  • :from (String, Integer, User)

    Matches the user who removed the reaction.

  • :message (String, Integer, Message)

    Matches the message to which the reaction was removed.

  • :in (String, Integer, Channel)

    Matches the channel the reaction was removed in.

  • :type (Integer, String, Symbol)

    Matches the type of reaction (:normal or :burst) that was added.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



160
161
162
# File 'lib/discordrb/container.rb', line 160

def reaction_remove(attributes = {}, &block)
  register_event(ReactionRemoveEvent, attributes, block)
end

#reaction_remove_all(attributes = {}) {|event| ... } ⇒ ReactionRemoveAllEventHandler

This event is raised when somebody removes all reactions from a message.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • The (Hash)

    event's attributes.

  • :message (String, Integer, Message)

    Matches the message to which the reactions were removed.

  • :in (String, Integer, Channel)

    Matches the channel the reactions were removed in.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



172
173
174
# File 'lib/discordrb/container.rb', line 172

def reaction_remove_all(attributes = {}, &block)
  register_event(ReactionRemoveAllEvent, attributes, block)
end

#reaction_remove_emoji(attributes = {}) {|event| ... } ⇒ ReactionRemoveEmojiEventHandler

This event is raised when somebody removes all instances of a single reaction from a message.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :message (String, Integer, Message)

    Matches the message where the reaction was removed.

  • :in (String, Integer, Channel)

    Matches the channel where the reaction was removed.

  • :emoji (String, Integer)

    Matches the ID of the emoji that was removed, or its name.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



184
185
186
# File 'lib/discordrb/container.rb', line 184

def reaction_remove_emoji(attributes = {}, &block)
  register_event(ReactionRemoveEmojiEvent, attributes, block)
end

#ready(attributes = {}) {|event| ... } ⇒ ReadyEventHandler

This event is raised when the READY packet is received, i.e. servers and channels have finished initialization. It's the recommended way to do things when the bot has finished starting up.

Parameters:

  • attributes (Hash) (defaults to: {})

    Event attributes, none in this particular case

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

  • event (ReadyEvent)

    The event that was raised.

Returns:



50
51
52
# File 'lib/discordrb/container.rb', line 50

def ready(attributes = {}, &block)
  register_event(ReadyEvent, attributes, block)
end

#remove_application_command_handler(name) ⇒ Object

Remove an application command handler

Parameters:

  • name (String, Symbol)

    The name of the command handler to remove.



731
732
733
# File 'lib/discordrb/container.rb', line 731

def remove_application_command_handler(name)
  @application_commands.delete(name)
end

#remove_handler(handler) ⇒ Object

Removes an event handler from this container. If you're looking for a way to do temporary events, I recommend Awaits instead of this.

Parameters:



723
724
725
726
727
# File 'lib/discordrb/container.rb', line 723

def remove_handler(handler)
  clazz = EventContainer.event_class(handler.class)
  @event_handlers ||= {}
  @event_handlers[clazz].delete(handler)
end

#role_select(attributes = {}) {|event| ... } ⇒ RoleSelectEventHandler

This event is raised whenever an select role interaction is created.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :custom_id (String, Regexp)

    A custom_id to match against.

  • :message (String, Integer, Message)

    The message to filter for.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



635
636
637
# File 'lib/discordrb/container.rb', line 635

def role_select(attributes = {}, &block)
  register_event(RoleSelectEvent, attributes, block)
end

#server_create(attributes = {}) {|event| ... } ⇒ ServerCreateEventHandler

This event is raised when a server is created respective to the bot, i.e. the bot joins a server or creates a new one itself.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



377
378
379
# File 'lib/discordrb/container.rb', line 377

def server_create(attributes = {}, &block)
  register_event(ServerCreateEvent, attributes, block)
end

#server_delete(attributes = {}) {|event| ... } ⇒ ServerDeleteEventHandler

This event is raised when a server is deleted, or when the bot leaves a server. (These two cases are identical to Discord.)

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



398
399
400
# File 'lib/discordrb/container.rb', line 398

def server_delete(attributes = {}, &block)
  register_event(ServerDeleteEvent, attributes, block)
end

#server_emoji(attributes = {}) {|event| ... } ⇒ ServerEmojiChangeEventHandler

This event is raised when an emoji or collection of emojis is created/deleted/updated.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



408
409
410
# File 'lib/discordrb/container.rb', line 408

def server_emoji(attributes = {}, &block)
  register_event(ServerEmojiChangeEvent, attributes, block)
end

#server_emoji_create(attributes = {}) {|event| ... } ⇒ ServerEmojiCreateEventHandler

This event is raised when an emoji is created.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



420
421
422
# File 'lib/discordrb/container.rb', line 420

def server_emoji_create(attributes = {}, &block)
  register_event(ServerEmojiCreateEvent, attributes, block)
end

#server_emoji_delete(attributes = {}) {|event| ... } ⇒ ServerEmojiDeleteEventHandler

This event is raised when an emoji is deleted.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



432
433
434
# File 'lib/discordrb/container.rb', line 432

def server_emoji_delete(attributes = {}, &block)
  register_event(ServerEmojiDeleteEvent, attributes, block)
end

#server_emoji_update(attributes = {}) {|event| ... } ⇒ ServerEmojiUpdateEventHandler

This event is raised when an emoji is updated.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :server (String, Integer, Server)

    Matches the server.

  • :id (String, Integer)

    Matches the ID of the emoji.

  • :name (String)

    Matches the name of the emoji.

  • :old_name (String)

    Matches the name of the emoji before the update.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



445
446
447
# File 'lib/discordrb/container.rb', line 445

def server_emoji_update(attributes = {}, &block)
  register_event(ServerEmojiUpdateEvent, attributes, block)
end

#server_role_create(attributes = {}) {|event| ... } ⇒ ServerRoleCreateEventHandler

This event is raised when a role is created.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :name (String)

    Matches the role name.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



455
456
457
# File 'lib/discordrb/container.rb', line 455

def server_role_create(attributes = {}, &block)
  register_event(ServerRoleCreateEvent, attributes, block)
end

#server_role_delete(attributes = {}) {|event| ... } ⇒ ServerRoleDeleteEventHandler

This event is raised when a role is deleted.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



465
466
467
# File 'lib/discordrb/container.rb', line 465

def server_role_delete(attributes = {}, &block)
  register_event(ServerRoleDeleteEvent, attributes, block)
end

#server_role_update(attributes = {}) {|event| ... } ⇒ ServerRoleUpdateEventHandler

This event is raised when a role is updated.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :name (String)

    Matches the role name.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



475
476
477
# File 'lib/discordrb/container.rb', line 475

def server_role_update(attributes = {}, &block)
  register_event(ServerRoleUpdateEvent, attributes, block)
end

#server_update(attributes = {}) {|event| ... } ⇒ ServerUpdateEventHandler

This event is raised when a server is updated, for example if the name or region has changed.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



387
388
389
# File 'lib/discordrb/container.rb', line 387

def server_update(attributes = {}, &block)
  register_event(ServerUpdateEvent, attributes, block)
end

#string_select(attributes = {}) {|event| ... } ⇒ StringSelectEventHandler Also known as: select_menu

This event is raised whenever an select string interaction is created.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :custom_id (String, Regexp)

    A custom_id to match against.

  • :message (String, Integer, Message)

    The message to filter for.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



598
599
600
# File 'lib/discordrb/container.rb', line 598

def string_select(attributes = {}, &block)
  register_event(StringSelectEvent, attributes, block)
end

#typing(attributes = {}) {|event| ... } ⇒ TypingEventHandler

This event is raised when somebody starts typing in a channel the bot is also in. The official Discord client would display the typing indicator for five seconds after receiving this event. If the user continues typing after five seconds, the event will be re-raised.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :in (String, Integer, Channel)

    Matches the channel where typing was started.

  • :from (String, Integer, User)

    Matches the user that started typing.

  • :after (Time)

    Matches a time after the time the typing started.

  • :before (Time)

    Matches a time before the time the typing started.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



90
91
92
# File 'lib/discordrb/container.rb', line 90

def typing(attributes = {}, &block)
  register_event(TypingEvent, attributes, block)
end

#unknown(attributes = {}) {|event| ... } ⇒ UnknownEventHandler

This event is raised for a dispatch received over the gateway that is not currently handled otherwise by discordrb.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :type (String, Symbol, Regexp)

    Matches the event type of the dispatch.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



716
717
718
# File 'lib/discordrb/container.rb', line 716

def unknown(attributes = {}, &block)
  register_event(UnknownEvent, attributes, block)
end

#user_ban(attributes = {}) {|event| ... } ⇒ UserBanEventHandler

This event is raised when a user is banned from a server.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



355
356
357
# File 'lib/discordrb/container.rb', line 355

def user_ban(attributes = {}, &block)
  register_event(UserBanEvent, attributes, block)
end

#user_select(attributes = {}) {|event| ... } ⇒ UserSelectEventHandler

This event is raised whenever an select user interaction is created.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :custom_id (String, Regexp)

    A custom_id to match against.

  • :message (String, Integer, Message)

    The message to filter for.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



624
625
626
# File 'lib/discordrb/container.rb', line 624

def user_select(attributes = {}, &block)
  register_event(UserSelectEvent, attributes, block)
end

#user_unban(attributes = {}) {|event| ... } ⇒ UserUnbanEventHandler

This event is raised when a user is unbanned from a server.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



366
367
368
# File 'lib/discordrb/container.rb', line 366

def user_unban(attributes = {}, &block)
  register_event(UserUnbanEvent, attributes, block)
end

#voice_server_update(attributes = {}) {|event| ... } ⇒ VoiceServerUpdateEventHandler

This event is raised when first connecting to a server's voice channel.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



313
314
315
# File 'lib/discordrb/container.rb', line 313

def voice_server_update(attributes = {}, &block)
  register_event(VoiceServerUpdateEvent, attributes, block)
end

#voice_state_update(attributes = {}) {|event| ... } ⇒ VoiceStateUpdateEventHandler

This event is raised when a user's voice state changes. This includes when a user joins, leaves, or moves between voice channels, as well as their mute and deaf status for themselves and on the server.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

Options Hash (attributes):

  • :from (String, Integer, User)

    Matches the user that sent the message.

  • :channel (String, Integer, Channel)

    Matches the voice channel the user has joined.

  • :old_channel (String, Integer, Channel)

    Matches the voice channel the user was in previously.

  • :mute (true, false)

    Matches whether or not the user is muted server-wide.

  • :deaf (true, false)

    Matches whether or not the user is deafened server-wide.

  • :self_mute (true, false)

    Matches whether or not the user is muted by the bot.

  • :self_deaf (true, false)

    Matches whether or not the user is deafened by the bot.

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



303
304
305
# File 'lib/discordrb/container.rb', line 303

def voice_state_update(attributes = {}, &block)
  register_event(VoiceStateUpdateEvent, attributes, block)
end

#webhook_update(attributes = {}) {|event| ... } ⇒ WebhookUpdateEventHandler

This event is raised when a webhook is updated.

Parameters:

  • attributes (Hash) (defaults to: {})

    The event's attributes.

  • attribute (Hash)

    a customizable set of options

Options Hash (attributes):

Yields:

  • The block is executed when the event is raised.

Yield Parameters:

Returns:



487
488
489
# File 'lib/discordrb/container.rb', line 487

def webhook_update(attributes = {}, &block)
  register_event(WebhookUpdateEvent, attributes, block)
end