nostrum

Elixir Discord Library

Github星跟踪图

Nostrum

Build Status
Join Discord

An Elixir library for the Discord API.

It is highly recommended to check out the
documentation first. It includes all of the
information listed here and more.

Installation

Add Nostrum as a dependency:

Stable

Stable documentation can be found here

def deps do
  [{:nostrum, "~> 0.4"}]
end

Dev

def deps do
  [{:nostrum, git: "https://github.com/Kraigie/nostrum.git"}]
end

Edit or create your config file:

The file should be located at /config/config.exs. To run Nostrum you need the
following two fields:

config :nostrum,
  token: "666", # The token of your bot as a string
  num_shards: 2 # The number of shards you want to run your bot under, or :auto.

For more information about the differences between dev and stable as well as
additional config parameters, please see the
documentation.

Example Usage

The below module needs to be started in some fashion to capture events. See
here
for a full example.

defmodule ExampleConsumer do
  use Nostrum.Consumer

  alias Nostrum.Api

  def start_link do
    Consumer.start_link(__MODULE__)
  end

  def handle_event({:MESSAGE_CREATE, msg, _ws_state}) do
    case msg.content do
      "ping!" ->
        Api.create_message(msg.channel_id, "I copy and pasted this code")
      _ ->
        :ignore
    end
  end

  # Default event handler, if you don't include this, your consumer WILL crash if
  # you don't have a method definition for each event type.
  def handle_event(_event) do
    :noop
  end
end

Although it's recommended to run under a supervisor, you could start it from iex.

  iex()> ExampleConsumer.start
  {:ok, #PID<0.208.0>}

Getting Help

If you need help, visit #elixir_nostrum on the unofficial Discord API guild!

Discord API

License

MIT

主要指标

概览
名称与所有者Kraigie/nostrum
主编程语言Elixir
编程语言Elixir (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2016-08-26 21:18:34
推送于2025-05-23 19:16:40
最后一次提交2025-05-23 21:14:49
发布数31
最新版本名称v0.10.4 (发布于 2025-03-02 21:40:50)
第一版名称0.2.0 (发布于 )
用户参与
星数668
关注者数13
派生数130
提交数1.8k
已启用问题?
问题数181
打开的问题数22
拉请求数434
打开的拉请求数4
关闭的拉请求数68
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?