Sha256: 3de3357db3fb20d9d4644bebd2d9f9814784604c29388ddf8d7ed7f6015a55d9

Contents?: true

Size: 1.56 KB

Versions: 6

Compression:

Stored size: 1.56 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::Command::Handler} module, so you can register command with {Discorb::Command::Handler#slash} and {Discorb::Command::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

6 entries across 6 versions & 1 rubygems

Version Path
discorb-0.6.0 docs/extension.md
discorb-0.5.6 docs/extension.md
discorb-0.5.5 docs/extension.md
discorb-0.5.4 docs/extension.md
discorb-0.5.3 docs/extension.md
discorb-0.5.2 docs/extension.md