disml

An OCaml library for interfacing with the Discord API
README

This is a library for creating bots on Discord. Dis.ml uses JaneStreet's Async and Core libs and I highly recommend having a solid understanding of both of these before using this library.

Docs can be found here.

State of the project

Latest changes are on master

What is implemented?
  • The full Discord REST API (Exposed through Disml.Http with abstractions on various models)

  • Complete gateway support (sans voice)

  • Automatic and manual sharding

  • Event dispatch to a user-defined consumer that can be changed at runtime

  • Automatic reconnection of dropped gateway connections, using RESUME when possible

  • Automatic rate limit handling for REST requests

  • Cache

What is not implemented?
  • Abstractions for Discord Objects (Mostly Completed)

  • Voice

Getting started

In order to get started you'll first need to install OCaml (of course). I recommend using OPAM and Dune as a package manager and build tool respectively.

The project is not currently uploaded to opam, but you can still install via opam by pinning to this repo.

opam pin add disml https://gitlab.com/Mishio595/disml.git

If you do not use opam, see disml.opam for build instructions.

You'll find an example bot in /bin directory.

Examples

Robust example

/bin/bot.ml

Basic example
open Async
open Core
open Disml
open Models

(* Create a function to handle message_create. *)
let check_command (message:Message.t) =
    if String.is_prefix ~prefix:"!ping" message.content then
        Message.reply message "Pong!" >>> ignore

let main () =
    (* Register the event handler *)
    Client.message_create := check_command;
    (* Start the client. It's recommended to load the token from an env var or other config file. *)
    Client.start "My token" >>> ignore

let _ =
    (* Launch the Async scheduler. You must do this for anything to work. *)
    Scheduler.go_main ~main ()
Install
Published
12 Feb 2019
Sources
0.2.5.tar.gz
md5=294333728fef442b30c13420c00a1441
sha512=9117726da1dc2b12589666c7550eea6b8d9ba15cb88bcbccbde7069660942a40c2ceaf54dd88f9deb1275840d65b23f6c118591a816a464f069e0fa1bb9d2dc0
Dependencies
yojson
< "1.6.0"
ppx_sexp_conv
>= "v0.11.2"
odoc
with-doc & >= "1.3.0"
decompress
>= "0.8" & < "0.9"
core
>= "v0.11.3"
cohttp-async
>= "1.2.0"
async_ssl
>= "v0.11.0"
dune
>= "1.3.0"
ocaml
>= "4.04.1"
Reverse Dependencies