satom99 / coxir

A modern Elixir wrapper for Discord.

Home Page:https://satom.me/coxir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

coxir

License Validation Documentation Join Discord

A modern high-level Elixir wrapper for Discord.

Refer to the documentation for more information.

Features

  • 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

Installation

Add coxir as a dependency to your mix.exs file:

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

Quickstart

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.

More

For more information check out the documentation guides.

About

A modern Elixir wrapper for Discord.

https://satom.me/coxir

License:Apache License 2.0


Languages

Language:Elixir 100.0%