aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: cee3d5486b498d31ec09f821ec622a0ed5be8424 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Dis.ml - An OCaml wrapper for the Discord API

This is a library for creating bots on [Discord](https://discordapp.com/). 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](https://mishio595.gitlab.io/disml).

## 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

```ocaml
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 ()
```