/coxir

An Elixir wrapper for Discord.

Primary LanguageElixirApache License 2.0Apache-2.0

coxir

License Build Status Join Discord Donate

An Elixir wrapper for Discord. Based on nostrum and alchemy.

Please refer to the documentation for more information on the library.

Installation

One should simply include coxir as a dependency as follows.

defp deps do
  [{:coxir, git: "https://github.com/satom99/coxir.git"}]
end

Getting started

Before setting up a consumer, coxir must be configured as follows.

config :coxir,
  token: "",
  shards: 1, # optional
  ffmpeg: "" # optional

In order to process incoming events, a consumer should be set up as follows.

defmodule Consumer do
  use Coxir

  def handle_event({:MESSAGE_CREATE, message}, state) do
    case message.content do
      "ping!" ->
        Message.reply(message, "pong!")
      _ ->
        :ignore
    end

    {:ok, state}
  end

  def handle_event(_event, state) do
    {:ok, state}
  end
end

Once all the above is done, the application may be configured in any desired fashion so that a consumer process is started.

defmodule Example do
  use Application
  use Supervisor

  def start(_type, _args) do
    children = [
      worker(Consumer, [])
    ]
    options = [
      strategy: :one_for_one,
      name: __MODULE__
    ]
    Supervisor.start_link(children, options)
  end
end

A common approach to which would be the above, of course after configuring the module as a callback.