Module: Discorb::Extension::ClassMethods
- Includes:
- ApplicationCommand::Handler
- Defined in:
- lib/discorb/extension.rb
Instance Attribute Summary collapse
-
#commands -> Array<Discorb::ApplicationCommand::Command>
readonly
The commands of the extension.
-
#events -> Hash{Symbol => Array<Discorb::EventHandler>}
readonly
The events of the extension.
Instance Method Summary collapse
-
#event(event_name, id: nil, **metadata, &block) -> Discorb::EventHandler
Define a new event.
-
#once_event(event_name, id: nil, **metadata, &block) -> Discorb::EventHandler
Define a new once event.
Methods included from ApplicationCommand::Handler
#message_command, #setup_commands, #slash, #slash_group, #user_command
Instance Attribute Details
#commands -> Array<Discorb::ApplicationCommand::Command> (readonly)
Returns The commands of the extension.
69 70 71 |
# File 'lib/discorb/extension.rb', line 69 def commands @commands end |
#events -> Hash{Symbol => Array<Discorb::EventHandler>} (readonly)
Returns The events of the extension.
67 68 69 |
# File 'lib/discorb/extension.rb', line 67 def events @events end |
Instance Method Details
#event(event_name, id: nil, **metadata, &block) -> Discorb::EventHandler
Define a new event.
43 44 45 46 47 48 49 50 |
# File 'lib/discorb/extension.rb', line 43 def event(event_name, id: nil, **, &block) raise ArgumentError, "Event name must be a symbol" unless event_name.is_a?(Symbol) raise ArgumentError, "block must be given" unless block_given? @events[event_name] ||= [] [:extension] = self.name @events[event_name] << [id, , block] end |
#once_event(event_name, id: nil, **metadata, &block) -> Discorb::EventHandler
Define a new once event.
62 63 64 |
# File 'lib/discorb/extension.rb', line 62 def once_event(event_name, id: nil, **, &block) event(event_name, id: id, once: true, **, &block) end |