@jnode/discord 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +117 -0
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1,2 +1,119 @@
1
1
  # JustDiscord
2
+
2
3
  Simple Discord API package for Node.js.
4
+
5
+ ```shell
6
+ npm install @jnode/discord
7
+ ```
8
+
9
+ ## Basic usage
10
+
11
+ ```js
12
+ // import JustDiscord
13
+ const discord = require('@jnode/discord');
14
+
15
+ // create a client
16
+ const client = new discord.Client('YOUR_BOT_TOKEN');
17
+
18
+ // connect to Discord gateway
19
+ client.connectGateway((gateway) => {
20
+ // receive Discord gateway "READY" event
21
+ gateway.on('READY', (d) => {
22
+ console.log('Connected to Discord.');
23
+ });
24
+ });
25
+ ```
26
+
27
+ ## DiscordClient
28
+
29
+ ### Constructor
30
+
31
+ ```js
32
+ constructor(token, options = {})
33
+ ```
34
+
35
+ * `token`: Your Discord bot token.
36
+ * `options`: An object containing client options.
37
+ * `apiVersion`: The Discord API version to use. (default: `10`)
38
+ * `apiBase`: The base URL for the Discord API. (default: `'discord.com/api'`)
39
+ * `apiAutoRetry`: Whether to automatically retry requests when receiving a 429 status code. (default: `true`)
40
+ * `apiThrowError`: Whether to throw an error when an API request returns a status code outside of the 2xx range. (default: `true`)
41
+ * `gatewayIntents`: The gateway intents to use. (default: `0b11111111111111111000110011`)
42
+ * `gatewayUrl`: The URL for the Discord gateway. (default: `'wss://gateway.discord.gg'`)
43
+ * `gatewayReconnectDelay`: The delay in milliseconds before attempting to reconnect to the gateway. (default: `5000`)
44
+ * `gatewayConnectTimeout`: The timeout in milliseconds for the gateway connection. (default: `5000`)
45
+ * `gatewayThrowError`: Whether to throw an error when the gateway encounters an issue. (default: `true`)
46
+
47
+ ### Methods
48
+
49
+ #### `apiUrl(path)`
50
+
51
+ Returns the full API URL with the base, version, and provided path.
52
+
53
+ * `path`: The API endpoint path.
54
+
55
+ #### `async apiRequest(method = 'GET', path = '/', body)`
56
+
57
+ Makes a request to the Discord API.
58
+
59
+ * `method`: The HTTP method (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`). (default: `'GET'`)
60
+ * `path`: The API endpoint path. (default: `'/'`)
61
+ * `body`: The request body (will be stringified to JSON). (optional)
62
+
63
+ #### `async apiRequestMultipart(method = 'GET', path = '/', body, attachments = [])`
64
+
65
+ Makes a multipart request to the Discord API.
66
+
67
+ * `method`: The HTTP method (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`). (default: `'GET'`)
68
+ * `path`: The API endpoint path. (default: `'/'`)
69
+ * `body`: The request body (will be stringified to JSON).
70
+ * `attachments`: An array of attachment objects. Each attachment object should have the following properties:
71
+ * `name`: The file name.
72
+ * `type`: The content type of the file.
73
+ * `data`: The file data (Buffer or Uint8Array).
74
+ * `encoded`: Boolean, should be true if the data has already been encoded.
75
+
76
+ #### `async connectGateway(cb)`
77
+
78
+ Connects to the Discord gateway.
79
+
80
+ * `cb`: A callback function that will be called with the `DiscordGateway` instance.
81
+
82
+ ## DiscordGateway
83
+
84
+ ### Events
85
+
86
+ * `socketOpened`: Emitted when the WebSocket connection is opened.
87
+ * `socketClosed`: Emitted when the WebSocket connection is closed.
88
+ * `socketError`: Emitted when an error occurs with the WebSocket connection.
89
+ * `socketMessage`: Emitted when a message is received from the WebSocket.
90
+ * `message`: Emitted when a message with json data is received from the WebSocket.
91
+ * `READY`: Emitted when the gateway sends a `READY` event.
92
+ * Other events may be emitted depending on the received `t` value, such as `MESSAGE_CREATE`, `GUILD_CREATE`.
93
+
94
+ ### Methods
95
+
96
+ #### `async getGatewayUrl()`
97
+
98
+ Gets the gateway URL from the Discord API.
99
+
100
+ #### `connect()`
101
+
102
+ Connects to the Discord gateway.
103
+
104
+ #### `sendMessage(op, d = null)`
105
+
106
+ Sends a message to the Discord gateway.
107
+
108
+ * `op`: The opcode of the message.
109
+ * `d`: The data of the message. (optional)
110
+
111
+ ## Errors
112
+
113
+ ### DiscordAPIError
114
+
115
+ Thrown when an API request returns a status code outside of the 2xx range.
116
+
117
+ * `code`: The HTTP status code.
118
+ * `body`: The response body.
119
+ * `headers`: The response headers.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jnode/discord",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Simple Discord API package for Node.js.",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -25,6 +25,6 @@
25
25
  "node": ">=22.4.0"
26
26
  },
27
27
  "dependencies": {
28
- "@jnode/request": "1.x.x"
28
+ "@jnode/request": ">=1.0.4 <2.0.0"
29
29
  }
30
30
  }