Sha256: 75e5d1d527eaf32a22a3be566dc213ba097b29d60af162f636ab421cf94eec35

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

# @title Extension

# Extension

Extension allows you to split your code into multiple files.

## Make a new extension

Make a new module, and extend {Discorb::Extension}.

```ruby
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.

```ruby
module MyExtension
  extend Discorb::Extension

  event :message do |message|
    # ...
  end

  once_event :ready do |message|
    # ...
  end
end
```

## Register Command

Since v0.5.2, {Discorb::Extension} includes {Discorb::ApplicationCommand::Handler} module, so you can register command with {Discorb::ApplicationCommand::Handler#slash} and {Discorb::ApplicationCommand::Handler#slash_group}.

```ruby
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.

```ruby
module MyExtension
  extend Discorb::Extension

  event :message do |message|
    # ...
  end
end

client.extend MyExtension
```

## Access Client from extension

You can access {Discorb::Client} from extension with `@client`.

```ruby
module MyExtension
  extend Discorb::Extension

  event :ready do |message|
    puts "Logged in as #{client.user}"
  end
end
```

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
discorb-0.6.1 docs/extension.md