blob: 3362bf9645e1f4010e531be9fa5bd3b1a52daaf1 (
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
(**
{2 Dis.ml - An OCaml library for interfacing with the Discord API}
{3 Example}
{[
open Async
open Core
open Disml
open Models
(* Create a function to handle message_create. *)
let check_command (Event.MessageCreate.{message}) =
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 ()
]}
*)
(** The primary interface for connecting to Discord and handling gateway events. *)
module Client = Client
(** Caching module. {!Cache.cache} is an {{!Async.Mvar.Read_write.t}Mvar}, which is always filled, containing an immutable cache record to allow for safe, concurrent access. *)
module Cache = Cache
(** Raw HTTP abstractions for Discord's REST API. *)
module Http = struct
include Http
(** Internal module for resolving endpoints *)
module Endpoints = Endpoints
(** Internal module for handling rate limiting *)
module Ratelimits = Rl
end
(** Gateway connection super module. *)
module Gateway = struct
(** Internal module used for dispatching events. *)
module Dispatch = Dispatch
(** Internal module for representing events. *)
module Event = Event
(** Internal module for representing Discord's opcodes. *)
module Opcode = Opcode
(** Shard manager *)
module Sharder = Sharder
end
(** Super module for all Discord object types. *)
module Models = struct
(** Represents a user's activity. *)
module Activity = Activity
(** Represents a message attachment. *)
module Attachment = Attachment
(** Represents a ban object. *)
module Ban = Ban
(** Represents a full channel object. *)
module Channel = Channel
(** Represents solely a channel ID. REST operations can be performed without the full object overhead using this. *)
module Channel_id = Channel_id
(** Represents an embed object. *)
module Embed = Embed
(** Represents an emoji, both custom and unicode. *)
module Emoji = Emoji
(** Represents a guild object, also called a server. *)
module Guild = Guild
(** Represents solely a guild ID. REST operations can be performed without the full object overhead using this. *)
module Guild_id = Guild_id
(** Represents a user in the context of a guild. *)
module Member = Member
(** Represents a message object in any channel. *)
module Message = Message
(** Represents solely a message ID. REST operations can be performed without the full object overhead using this. *)
module Message_id = Message_id
(** Represents a user presence. See {!Models.Event.PresenceUpdate}. *)
module Presence = Presence
(** Represents an emoji used to react to a message. *)
module Reaction = Reaction
(** Represents a role object. *)
module Role = Role
(** Represents solely a role ID. REST operations can be performed without the full object overhead using this. *)
module Role_id = Role_id
(** Represents a Discord ID. *)
module Snowflake = Snowflake
(** Represents a user object. *)
module User = User
(** Represents solely a user ID. REST operations can be performed without the full object overhead using this. *)
module User_id = User_id
(** Represents the structures received over the gateway. *)
module Event = Event_models
end
|