Code Monkey home page Code Monkey logo

nostrum's Introduction

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

nostrum's People

Contributors

andris0 avatar awlexus avatar connorrigby avatar cookkkie avatar cronokirby avatar dazeycm avatar defnorep avatar geopjr avatar jb3 avatar jchristgit avatar jmajeski avatar kevinkjt2000 avatar kraigie avatar lazyshpee avatar mokou avatar ndac-todoroki avatar pixelinc avatar ppraisethesun avatar queer avatar sapphiccode avatar skippi avatar sn0wmobil avatar thatsnomoon avatar unleashy avatar xh4h avatar z64 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.