Sha256: fce2415a89fe7f0f5ca49eb9b96fb9db95dfd5a77141d85ed06f34b88432e979

Contents?: true

Size: 984 Bytes

Versions: 8

Compression:

Stored size: 984 Bytes

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

## 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

8 entries across 8 versions & 1 rubygems

Version Path
discorb-0.5.1 docs/extension.md
discorb-0.5.0 docs/extension.md
discorb-0.4.2 docs/extension.md
discorb-0.4.1 docs/extension.md
discorb-0.4.0 docs/extension.md
discorb-0.3.1 docs/extension.md
discorb-0.3.0 docs/extension.md
discorb-0.2.5 docs/extension.md