Extension
Extension allows you to split your code into multiple files.
Make a new extension
Make a new module, and extend Discorb::Extension.
module MyExtension
extend Discorb::Extension
# ...
end
Register Event
Use Discorb::Extension.event to register event, or Discorb::Extension.once_event to register event only once.
module MyExtension
extend Discorb::Extension
event :message do ||
# ...
end
once_event :ready do ||
# ...
end
end
Register Command
Since v0.5.2, Discorb::Extension includes Discorb::Command::Handler module, so you can register command with Discorb::Command::Handler#slash and Discorb::Command::Handler#slash_group.
module MyExtension
extend Discorb::Extension
slash("command", "Command") do |interaction|
# ...
end
slash_group("group", "Group") do
slash("subcommand", "Subcommand") do |interaction|
# ...
end
group("subgroup", "Subcommand group") do
slash("group_subcommand", "Command in Subcommand group") do |interaction|
# ...
end
end
end
end
Load extension
Use Discorb::Client#extend to load extension.
module MyExtension
extend Discorb::Extension
event :message do ||
# ...
end
end
client.extend MyExtension
Access Client from extension
You can access Discorb::Client from extension with @client
.
module MyExtension
extend Discorb::Extension
event :ready do ||
puts "Logged in as #{client.user}"
end
end