A modern high-level Elixir wrapper for Discord.
Refer to the documentation for more information.
- Support for running multiple bots in a same application
- Configurable adapters that change how the library behaves:
- Limiter: handles how rate limit buckets are stored
- Storage: handles how entities are cached
- Sharder: handles how shards are started
- Player: handles the audio sent through voice
- Easy-to-use syntax for interacting with Discord entities
Add coxir as a dependency to your mix.exs
file:
defp deps do
[{:coxir, git: "https://github.com/satom99/coxir.git"}]
end
Before consuming events, coxir must be configured:
config :coxir,
token: "",
intents: :non_privileged # optional
Then a simple consumer can be set up as follows:
defmodule Example.Bot do
use Coxir.Gateway
alias Coxir.{User, Message}
def handle_event({:MESSAGE_CREATE, %Message{content: "!hello"} = message}) do
%Message{author: author} = Message.preload(message, :author)
%User{username: username, discriminator: discriminator} = author
Message.reply(message, content: "Hello #{username}##{discriminator}!")
end
def handle_event(_event) do
:noop
end
end
Which can then be added to a Supervisor, or started directly:
iex(1)> Example.Bot.start_link()
{:ok, #PID<0.301.0>}
For a complete and working example check out the example
app.
For more information check out the documentation guides.