@jnode/discord 1.0.10 → 1.0.12
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.
- package/README.md +7 -1
- package/package.json +2 -2
- package/src/client.js +10 -9
package/README.md
CHANGED
|
@@ -77,7 +77,13 @@ new discord.Client(token, options = {})
|
|
|
77
77
|
- `method`: HTTP method (e.g. `GET`, `POST`, `PUT`, `DELETE`). Default is `GET`.
|
|
78
78
|
- `path`: API endpoint path. Default is `/`. Example: `/channels/123456789/messages`.
|
|
79
79
|
- `body`: Request body data (will be stringified). Example: `{ content: 'Hello, Discord!' }`.
|
|
80
|
-
- `attachments`: An array of attachments, each attachment is an object
|
|
80
|
+
- `attachments`: An array of attachments, each attachment is an object:
|
|
81
|
+
- `name`: Name of the file. Example: `image.png`
|
|
82
|
+
- `type` (Optional): Content type of the data. Defaults to `application/octet-stream`.
|
|
83
|
+
- `data` (Option 1): Data (string or Buffer) of this file.
|
|
84
|
+
- `file` (Option 2): Path to a local file.
|
|
85
|
+
- `encoded`/`base64` (Option 3): base64 encoded data string.
|
|
86
|
+
- `stream` (Option 4): Any readable stream.
|
|
81
87
|
- **Returns**: `Promise<RequestResponse>` - A promise that resolves to a `RequestResponse` object.
|
|
82
88
|
- **Example**:
|
|
83
89
|
```js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jnode/discord",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
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.
|
|
28
|
+
"@jnode/request": ">=1.1.3 <2.0.0"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/client.js
CHANGED
|
@@ -76,25 +76,26 @@ class DiscordClient {
|
|
|
76
76
|
async apiRequestMultipart(method = 'GET', path = '/', body, attachments = []) {
|
|
77
77
|
let parts = [];
|
|
78
78
|
parts.push({ //json data
|
|
79
|
-
disposition: 'name="payload_json"',
|
|
80
|
-
|
|
79
|
+
disposition: 'form-data; name="payload_json"',
|
|
80
|
+
type: 'application/json',
|
|
81
81
|
data: JSON.stringify(body)
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
for (let i = 0; i < attachments.length; i++) { //add every attachment
|
|
85
85
|
parts.push({
|
|
86
|
-
disposition: `name="files[${i}]"; filename="${encodeURIComponent(attachments[i].name)}"`,
|
|
87
|
-
|
|
86
|
+
disposition: `form-data; name="files[${i}]"; filename="${encodeURIComponent(attachments[i].name)}"`,
|
|
87
|
+
type: attachments[i].type,
|
|
88
88
|
data: attachments[i].data,
|
|
89
|
-
|
|
89
|
+
base64: attachments[i].encoded ?? attachments[i].base64,
|
|
90
|
+
stream: attachments[i].stream,
|
|
91
|
+
file: attachments[i].file
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
|
|
93
|
-
const res = await request.
|
|
95
|
+
const res = await request.multipartRequest(method, this.apiUrl(path), {
|
|
94
96
|
'Authorization': `Bot ${this.token}`,
|
|
95
|
-
'User-Agent': 'DiscordBot'
|
|
96
|
-
|
|
97
|
-
}, request.generateMultipartBody(parts)); //make an request
|
|
97
|
+
'User-Agent': 'DiscordBot'
|
|
98
|
+
}, parts); //make an request
|
|
98
99
|
|
|
99
100
|
if ((res.code === 429) && this.apiAutoRetry) { //retry if recieved 429
|
|
100
101
|
await delay(res.json().retry_after);
|