@imaentity/selfjs 4.0.1 → 4.1.0
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/docs.md +361 -67
- package/package.json +1 -1
- package/self.js +150 -2
package/docs.md
CHANGED
|
@@ -17,8 +17,6 @@ npm install @imaentity/selfjs
|
|
|
17
17
|
const self = require("@imaentity/selfjs");
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
---
|
|
21
|
-
|
|
22
20
|
# Constants
|
|
23
21
|
|
|
24
22
|
## `Status`
|
|
@@ -34,8 +32,6 @@ Status.CUSTOM_STATUS // 4
|
|
|
34
32
|
Status.COMPETING // 5
|
|
35
33
|
```
|
|
36
34
|
|
|
37
|
-
---
|
|
38
|
-
|
|
39
35
|
# Functions
|
|
40
36
|
|
|
41
37
|
## `validateToken(token)`
|
|
@@ -67,14 +63,10 @@ else
|
|
|
67
63
|
console.log("Invalid token");
|
|
68
64
|
```
|
|
69
65
|
|
|
70
|
-
---
|
|
71
|
-
|
|
72
66
|
## `createToken(options)`
|
|
73
67
|
|
|
74
|
-
Attempts to log into a Discord account using an email and password.
|
|
75
|
-
|
|
76
|
-
If MFA is not enabled, the returned object contains the token immediately.
|
|
77
|
-
|
|
68
|
+
Attempts to log into a Discord account using an email and password.
|
|
69
|
+
If MFA is not enabled, the returned object contains the token immediately.
|
|
78
70
|
If MFA is required, the returned object contains the available MFA methods and a `confirmMFA()` function.
|
|
79
71
|
|
|
80
72
|
### Parameters
|
|
@@ -136,15 +128,12 @@ if(!login.mfaRequired) {
|
|
|
136
128
|
}
|
|
137
129
|
```
|
|
138
130
|
|
|
139
|
-
> [!NOTE]
|
|
131
|
+
> [!NOTE]
|
|
140
132
|
> SMS MFA is currently unsupported.
|
|
141
133
|
|
|
142
|
-
---
|
|
143
|
-
|
|
144
134
|
## `snowflakeToUTC(snowflake)`
|
|
145
135
|
|
|
146
|
-
Converts a Discord snowflake into a UTC timestamp.
|
|
147
|
-
|
|
136
|
+
Converts a Discord snowflake into a UTC timestamp.
|
|
148
137
|
The returned timestamp is in milliseconds since Unix epoch.
|
|
149
138
|
|
|
150
139
|
### Parameters
|
|
@@ -167,12 +156,9 @@ const timestamp = self.snowflakeToUTC("1329029486758592595");
|
|
|
167
156
|
console.log(new Date(timestamp));
|
|
168
157
|
```
|
|
169
158
|
|
|
170
|
-
---
|
|
171
|
-
|
|
172
159
|
## `UTCToSnowflake(timestamp)`
|
|
173
160
|
|
|
174
|
-
Converts a UTC timestamp into a Discord snowflake.
|
|
175
|
-
|
|
161
|
+
Converts a UTC timestamp into a Discord snowflake.
|
|
176
162
|
The generated snowflake only contains the timestamp portion. Worker ID, process ID, and sequence values are zero.
|
|
177
163
|
|
|
178
164
|
### Parameters
|
|
@@ -195,8 +181,6 @@ const snowflake = self.UTCToSnowflake(Date.now());
|
|
|
195
181
|
console.log(snowflake);
|
|
196
182
|
```
|
|
197
183
|
|
|
198
|
-
---
|
|
199
|
-
|
|
200
184
|
# Client
|
|
201
185
|
|
|
202
186
|
`Client` provides an interface for connecting to Discord and interacting with the account.
|
|
@@ -229,8 +213,6 @@ const client = new self.Client({
|
|
|
229
213
|
| `debugLogs` | `Boolean` | `true` | Enables SelfJS debug logging. |
|
|
230
214
|
| `intents` | `Number` | `null` | Gateway intents, used for bot accounts. |
|
|
231
215
|
|
|
232
|
-
---
|
|
233
|
-
|
|
234
216
|
# Properties
|
|
235
217
|
|
|
236
218
|
## `client.user`
|
|
@@ -243,8 +225,6 @@ console.log(client.user);
|
|
|
243
225
|
|
|
244
226
|
This is populated after the `READY` event.
|
|
245
227
|
|
|
246
|
-
---
|
|
247
|
-
|
|
248
228
|
## `client.token`
|
|
249
229
|
|
|
250
230
|
The token currently being used by the client.
|
|
@@ -253,8 +233,6 @@ The token currently being used by the client.
|
|
|
253
233
|
console.log(client.token);
|
|
254
234
|
```
|
|
255
235
|
|
|
256
|
-
---
|
|
257
|
-
|
|
258
236
|
## `client.latency`
|
|
259
237
|
|
|
260
238
|
The time between sending a heartbeat and receiving its acknowledgement.
|
|
@@ -265,8 +243,6 @@ console.log(client.latency);
|
|
|
265
243
|
|
|
266
244
|
The value is in milliseconds.
|
|
267
245
|
|
|
268
|
-
---
|
|
269
|
-
|
|
270
246
|
# Login
|
|
271
247
|
|
|
272
248
|
## `client.login(token)`
|
|
@@ -287,8 +263,6 @@ client.login(token);
|
|
|
287
263
|
|
|
288
264
|
Once connected, events can be received using `client.on()`.
|
|
289
265
|
|
|
290
|
-
---
|
|
291
|
-
|
|
292
266
|
# Events
|
|
293
267
|
|
|
294
268
|
`Client` extends Node.js `EventEmitter`, so events can be listened to using `.on()`.
|
|
@@ -309,8 +283,6 @@ client.on("READY", data => {
|
|
|
309
283
|
});
|
|
310
284
|
```
|
|
311
285
|
|
|
312
|
-
---
|
|
313
|
-
|
|
314
286
|
## `MESSAGE_CREATE`
|
|
315
287
|
|
|
316
288
|
Emitted when a message is received.
|
|
@@ -350,8 +322,6 @@ client.on("MESSAGE_CREATE", message => {
|
|
|
350
322
|
});
|
|
351
323
|
```
|
|
352
324
|
|
|
353
|
-
---
|
|
354
|
-
|
|
355
325
|
## `DISCONNECT`
|
|
356
326
|
|
|
357
327
|
Emitted when the Gateway connection closes.
|
|
@@ -362,8 +332,6 @@ client.on("DISCONNECT", () => {
|
|
|
362
332
|
});
|
|
363
333
|
```
|
|
364
334
|
|
|
365
|
-
---
|
|
366
|
-
|
|
367
335
|
## `INVALID_SESSION`
|
|
368
336
|
|
|
369
337
|
Emitted when Discord invalidates the current session and it cannot be resumed.
|
|
@@ -374,8 +342,6 @@ client.on("INVALID_SESSION", () => {
|
|
|
374
342
|
});
|
|
375
343
|
```
|
|
376
344
|
|
|
377
|
-
---
|
|
378
|
-
|
|
379
345
|
# Messages
|
|
380
346
|
|
|
381
347
|
## `client.sendMessage(message)`
|
|
@@ -436,8 +402,6 @@ await client.sendMessage({
|
|
|
436
402
|
});
|
|
437
403
|
```
|
|
438
404
|
|
|
439
|
-
---
|
|
440
|
-
|
|
441
405
|
## `client.editMessage(message)`
|
|
442
406
|
|
|
443
407
|
Edits an existing message.
|
|
@@ -462,8 +426,6 @@ await client.editMessage({
|
|
|
462
426
|
});
|
|
463
427
|
```
|
|
464
428
|
|
|
465
|
-
---
|
|
466
|
-
|
|
467
429
|
## `client.getMessages(options)`
|
|
468
430
|
|
|
469
431
|
Gets recent messages from a channel.
|
|
@@ -493,8 +455,6 @@ const messages = await client.getMessages({
|
|
|
493
455
|
});
|
|
494
456
|
```
|
|
495
457
|
|
|
496
|
-
---
|
|
497
|
-
|
|
498
458
|
## `client.ackMessage(message)`
|
|
499
459
|
|
|
500
460
|
Acknowledges a message, removing its unread notification.
|
|
@@ -521,8 +481,6 @@ await client.ackMessage({
|
|
|
521
481
|
});
|
|
522
482
|
```
|
|
523
483
|
|
|
524
|
-
---
|
|
525
|
-
|
|
526
484
|
# Reactions
|
|
527
485
|
|
|
528
486
|
## `client.addReaction(options)`
|
|
@@ -547,8 +505,6 @@ await client.addReaction({
|
|
|
547
505
|
});
|
|
548
506
|
```
|
|
549
507
|
|
|
550
|
-
---
|
|
551
|
-
|
|
552
508
|
## `client.removeReaction(options)`
|
|
553
509
|
|
|
554
510
|
Removes the client's reaction from a message.
|
|
@@ -571,9 +527,25 @@ await client.removeReaction({
|
|
|
571
527
|
});
|
|
572
528
|
```
|
|
573
529
|
|
|
574
|
-
|
|
530
|
+
# Channels
|
|
575
531
|
|
|
576
|
-
|
|
532
|
+
## `client.getOpenChannels()`
|
|
533
|
+
|
|
534
|
+
Gets the channels currently present in the account's DM list.
|
|
535
|
+
This can contain both direct messages and group DMs.
|
|
536
|
+
|
|
537
|
+
### Returns
|
|
538
|
+
|
|
539
|
+
```javascript
|
|
540
|
+
Promise<Object>
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### Example
|
|
544
|
+
|
|
545
|
+
```javascript
|
|
546
|
+
const channels = await client.getOpenChannels();
|
|
547
|
+
console.log(channels);
|
|
548
|
+
```
|
|
577
549
|
|
|
578
550
|
## `client.search(options)`
|
|
579
551
|
|
|
@@ -650,15 +622,16 @@ const results = await client.search({
|
|
|
650
622
|
});
|
|
651
623
|
```
|
|
652
624
|
|
|
653
|
-
---
|
|
654
625
|
|
|
655
|
-
|
|
626
|
+
## `client.createGroupDM(recipients)`
|
|
656
627
|
|
|
657
|
-
|
|
628
|
+
Creates a group DM with the specified users.
|
|
658
629
|
|
|
659
|
-
|
|
630
|
+
### Parameters
|
|
660
631
|
|
|
661
|
-
|
|
632
|
+
| Name | Type | Description |
|
|
633
|
+
| ------------ | --------------- | ----------------------------- |
|
|
634
|
+
| `recipients` | `Array<String>` | User IDs to add to the group. |
|
|
662
635
|
|
|
663
636
|
### Returns
|
|
664
637
|
|
|
@@ -666,14 +639,343 @@ This can contain both direct messages and group DMs.
|
|
|
666
639
|
Promise<Object>
|
|
667
640
|
```
|
|
668
641
|
|
|
642
|
+
The new channel object.
|
|
643
|
+
|
|
669
644
|
### Example
|
|
670
645
|
|
|
671
646
|
```javascript
|
|
672
|
-
const
|
|
673
|
-
|
|
647
|
+
const group = await client.createGroupDM([
|
|
648
|
+
"123456789",
|
|
649
|
+
"987654321"
|
|
650
|
+
]);
|
|
651
|
+
|
|
652
|
+
console.log(group.id);
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
## `client.addToGroup(options)`
|
|
656
|
+
|
|
657
|
+
Adds a user to a group DM. The logged-in account must be friends with the user.
|
|
658
|
+
|
|
659
|
+
### Parameters
|
|
660
|
+
|
|
661
|
+
| Name | Type | Description |
|
|
662
|
+
| -------------------- | -------- | -------------------- |
|
|
663
|
+
| `options.channel_id` | `String` | Group DM channel ID. |
|
|
664
|
+
| `options.user_id` | `String` | User ID to add. |
|
|
665
|
+
|
|
666
|
+
### Returns
|
|
667
|
+
|
|
668
|
+
```javascript
|
|
669
|
+
Promise<void>
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
### Example
|
|
673
|
+
|
|
674
|
+
```javascript
|
|
675
|
+
await client.addToGroup({
|
|
676
|
+
channel_id: "123456789",
|
|
677
|
+
user_id: "987654321"
|
|
678
|
+
});
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
## `client.removeFromGroup(options)`
|
|
682
|
+
|
|
683
|
+
Removes a user from a group DM. The logged-in account must own the group.
|
|
684
|
+
|
|
685
|
+
### Parameters
|
|
686
|
+
|
|
687
|
+
| Name | Type | Description |
|
|
688
|
+
| -------------------- | -------- | -------------------- |
|
|
689
|
+
| `options.channel_id` | `String` | Group DM channel ID. |
|
|
690
|
+
| `options.user_id` | `String` | User ID to remove. |
|
|
691
|
+
|
|
692
|
+
### Returns
|
|
693
|
+
|
|
694
|
+
```javascript
|
|
695
|
+
Promise<void>
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
### Example
|
|
699
|
+
|
|
700
|
+
```javascript
|
|
701
|
+
await client.removeFromGroup({
|
|
702
|
+
channel_id: "123456789",
|
|
703
|
+
user_id: "987654321"
|
|
704
|
+
});
|
|
674
705
|
```
|
|
675
706
|
|
|
676
|
-
|
|
707
|
+
## `client.transferGroup(options)`
|
|
708
|
+
|
|
709
|
+
Transfers ownership of a group DM to another member.
|
|
710
|
+
|
|
711
|
+
### Parameters
|
|
712
|
+
|
|
713
|
+
| Name | Type | Description |
|
|
714
|
+
| -------------------- | -------- | ----------------------------- |
|
|
715
|
+
| `options.channel_id` | `String` | Group DM channel ID. |
|
|
716
|
+
| `options.user_id` | `String` | User ID to give ownership to. |
|
|
717
|
+
|
|
718
|
+
### Returns
|
|
719
|
+
|
|
720
|
+
```javascript
|
|
721
|
+
Promise<Object>
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
The updated channel object.
|
|
725
|
+
|
|
726
|
+
### Example
|
|
727
|
+
|
|
728
|
+
```javascript
|
|
729
|
+
const group = await client.transferGroup({
|
|
730
|
+
channel_id: "123456789",
|
|
731
|
+
user_id: "987654321"
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
console.log(group.owner_id);
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
## `client.leaveGroup(options)`
|
|
738
|
+
|
|
739
|
+
Leaves a group DM.
|
|
740
|
+
|
|
741
|
+
### Parameters
|
|
742
|
+
|
|
743
|
+
| Name | Type | Description |
|
|
744
|
+
| -------------------- | --------- | -------------------------------------------------- |
|
|
745
|
+
| `options.channel_id` | `String` | Group DM channel ID. |
|
|
746
|
+
| `options.silent` | `Boolean` | If `true`, does not notify the group of the leave. |
|
|
747
|
+
|
|
748
|
+
### Returns
|
|
749
|
+
|
|
750
|
+
```javascript
|
|
751
|
+
Promise<Object>
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
### Example
|
|
755
|
+
|
|
756
|
+
```javascript
|
|
757
|
+
await client.leaveGroup({
|
|
758
|
+
channel_id: "123456789",
|
|
759
|
+
silent: true
|
|
760
|
+
});
|
|
761
|
+
```
|
|
762
|
+
|
|
763
|
+
## `client.startTyping(channel_id)`
|
|
764
|
+
|
|
765
|
+
Starts the typing indicator in a channel.
|
|
766
|
+
The indicator lasts for 10 seconds. Calling this again before it expires resets the timer. Sending a message clears the indicator.
|
|
767
|
+
|
|
768
|
+
### Parameters
|
|
769
|
+
|
|
770
|
+
| Name | Type | Description |
|
|
771
|
+
| ------------ | -------- | ------------------------------ |
|
|
772
|
+
| `channel_id` | `String` | Channel ID to start typing in. |
|
|
773
|
+
|
|
774
|
+
### Returns
|
|
775
|
+
|
|
776
|
+
```javascript
|
|
777
|
+
Promise<void>
|
|
778
|
+
```
|
|
779
|
+
|
|
780
|
+
### Example
|
|
781
|
+
|
|
782
|
+
```javascript
|
|
783
|
+
await client.startTyping("123456789");
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
## `client.pinMessage(options)`
|
|
787
|
+
|
|
788
|
+
Pins a message in a channel.
|
|
789
|
+
|
|
790
|
+
### Parameters
|
|
791
|
+
|
|
792
|
+
| Name | Type | Description |
|
|
793
|
+
| -------------------- | -------- | ----------- |
|
|
794
|
+
| `options.channel_id` | `String` | Channel ID. |
|
|
795
|
+
| `options.message_id` | `String` | Message ID. |
|
|
796
|
+
|
|
797
|
+
### Returns
|
|
798
|
+
|
|
799
|
+
```javascript
|
|
800
|
+
Promise<void>
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
### Example
|
|
804
|
+
|
|
805
|
+
```javascript
|
|
806
|
+
await client.pinMessage({
|
|
807
|
+
channel_id: "123456789",
|
|
808
|
+
message_id: "987654321"
|
|
809
|
+
});
|
|
810
|
+
```
|
|
811
|
+
|
|
812
|
+
## `client.unpinMessage(options)`
|
|
813
|
+
|
|
814
|
+
Unpins a message from a channel.
|
|
815
|
+
|
|
816
|
+
### Parameters
|
|
817
|
+
|
|
818
|
+
| Name | Type | Description |
|
|
819
|
+
| -------------------- | -------- | ----------- |
|
|
820
|
+
| `options.channel_id` | `String` | Channel ID. |
|
|
821
|
+
| `options.message_id` | `String` | Message ID. |
|
|
822
|
+
|
|
823
|
+
### Returns
|
|
824
|
+
|
|
825
|
+
```javascript
|
|
826
|
+
Promise<void>
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
### Example
|
|
830
|
+
|
|
831
|
+
```javascript
|
|
832
|
+
await client.unpinMessage({
|
|
833
|
+
channel_id: "123456789",
|
|
834
|
+
message_id: "987654321"
|
|
835
|
+
});
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
## `client.getChannelObject(channel_id)`
|
|
839
|
+
|
|
840
|
+
Gets the current channel object using its ID.
|
|
841
|
+
This works for DMs, group DMs, server text channels, and server voice channels.
|
|
842
|
+
|
|
843
|
+
### Parameters
|
|
844
|
+
|
|
845
|
+
| Name | Type | Description |
|
|
846
|
+
| ------------ | -------- | ----------- |
|
|
847
|
+
| `channel_id` | `String` | Channel ID. |
|
|
848
|
+
|
|
849
|
+
### Returns
|
|
850
|
+
|
|
851
|
+
```javascript
|
|
852
|
+
Promise<Object>
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
The current channel object.
|
|
856
|
+
|
|
857
|
+
### Example
|
|
858
|
+
|
|
859
|
+
```javascript
|
|
860
|
+
const channel = await client.getChannelObject("123456789");
|
|
861
|
+
|
|
862
|
+
console.log(channel);
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
## `client.getDMChannel(user_id)`
|
|
866
|
+
|
|
867
|
+
Gets the channel object for DMs with a certain user
|
|
868
|
+
Getting the channel object also opens the channel in the active DM list
|
|
869
|
+
|
|
870
|
+
### Parameters
|
|
871
|
+
|
|
872
|
+
| Name | Type | Description |
|
|
873
|
+
| --------- | -------- | ----------- |
|
|
874
|
+
| `user_id` | `String` | User ID. |
|
|
875
|
+
|
|
876
|
+
### Returns
|
|
877
|
+
|
|
878
|
+
```javascript
|
|
879
|
+
Promise<Object>
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
The DM channel object.
|
|
883
|
+
|
|
884
|
+
### Example
|
|
885
|
+
|
|
886
|
+
```javascript
|
|
887
|
+
const channel = await client.getDMChannel("123456789");
|
|
888
|
+
|
|
889
|
+
console.log(channel);
|
|
890
|
+
```
|
|
891
|
+
|
|
892
|
+
## `client.closeDMChannel(user_id)`
|
|
893
|
+
|
|
894
|
+
Closes and hides the DM channel for a certain user from the active list
|
|
895
|
+
|
|
896
|
+
### Parameters
|
|
897
|
+
|
|
898
|
+
| Name | Type | Description |
|
|
899
|
+
| --------- | -------- | ----------- |
|
|
900
|
+
| `user_id` | `String` | User ID. |
|
|
901
|
+
|
|
902
|
+
### Returns
|
|
903
|
+
|
|
904
|
+
```javascript
|
|
905
|
+
Promise<Object>
|
|
906
|
+
```
|
|
907
|
+
|
|
908
|
+
The DM channel object.
|
|
909
|
+
|
|
910
|
+
### Example
|
|
911
|
+
|
|
912
|
+
```javascript
|
|
913
|
+
const channel = await client.getDMChannel("123456789");
|
|
914
|
+
|
|
915
|
+
console.log(channel);
|
|
916
|
+
```
|
|
917
|
+
|
|
918
|
+
# Users
|
|
919
|
+
|
|
920
|
+
## `client.getUserProfile(options)`
|
|
921
|
+
|
|
922
|
+
Gets a user's profile.
|
|
923
|
+
The request succeeds if at least one of these is true:
|
|
924
|
+
|
|
925
|
+
* The client shares a server with the user.
|
|
926
|
+
* The client is friends with the user.
|
|
927
|
+
* The user has sent a friend request to the client.
|
|
928
|
+
* The user is a bot.
|
|
929
|
+
|
|
930
|
+
### Parameters
|
|
931
|
+
|
|
932
|
+
| Name | Type | Description |
|
|
933
|
+
| ----------------------------------- | --------- | ---------------------------------------------- |
|
|
934
|
+
| `options` | `Object` | Profile request options. |
|
|
935
|
+
| `options.user_id` | `String` | ID of the user to get. |
|
|
936
|
+
| `options.with_mutual_guilds` | `Boolean` | Include mutual servers. Defaults to `true`. |
|
|
937
|
+
| `options.with_mutual_friends` | `Boolean` | Include mutual friends. |
|
|
938
|
+
| `options.with_mutual_friends_count` | `Boolean` | Include the number of mutual friends. |
|
|
939
|
+
| `options.guild_id` | `String` | Get the user's server profile for this server. |
|
|
940
|
+
|
|
941
|
+
### Returns
|
|
942
|
+
|
|
943
|
+
```javascript
|
|
944
|
+
Promise<Object>
|
|
945
|
+
```
|
|
946
|
+
|
|
947
|
+
The user's profile.
|
|
948
|
+
|
|
949
|
+
If none of the access conditions are met, Discord returns a `404` error.
|
|
950
|
+
|
|
951
|
+
### Example
|
|
952
|
+
|
|
953
|
+
```javascript
|
|
954
|
+
const profile = await client.getUserProfile({
|
|
955
|
+
user_id: "123456789"
|
|
956
|
+
});
|
|
957
|
+
|
|
958
|
+
console.log(profile);
|
|
959
|
+
```
|
|
960
|
+
|
|
961
|
+
### Example with mutual friends
|
|
962
|
+
|
|
963
|
+
```javascript
|
|
964
|
+
const profile = await client.getUserProfile({
|
|
965
|
+
user_id: "123456789",
|
|
966
|
+
with_mutual_friends: true,
|
|
967
|
+
with_mutual_friends_count: true
|
|
968
|
+
});
|
|
969
|
+
```
|
|
970
|
+
|
|
971
|
+
### Example with a server profile
|
|
972
|
+
|
|
973
|
+
```javascript
|
|
974
|
+
const profile = await client.getUserProfile({
|
|
975
|
+
user_id: "123456789",
|
|
976
|
+
guild_id: "987654321"
|
|
977
|
+
});
|
|
978
|
+
```
|
|
677
979
|
|
|
678
980
|
# Status
|
|
679
981
|
|
|
@@ -738,8 +1040,6 @@ client.setStatus({
|
|
|
738
1040
|
});
|
|
739
1041
|
```
|
|
740
1042
|
|
|
741
|
-
---
|
|
742
|
-
|
|
743
1043
|
# Authentication
|
|
744
1044
|
|
|
745
1045
|
## `client.logout()`
|
|
@@ -758,8 +1058,6 @@ Promise<Object>
|
|
|
758
1058
|
await client.logout();
|
|
759
1059
|
```
|
|
760
1060
|
|
|
761
|
-
---
|
|
762
|
-
|
|
763
1061
|
# Connection
|
|
764
1062
|
|
|
765
1063
|
## `client.disconnect(code)`
|
|
@@ -786,8 +1084,6 @@ Or with a specific close code:
|
|
|
786
1084
|
client.disconnect(1000);
|
|
787
1085
|
```
|
|
788
1086
|
|
|
789
|
-
---
|
|
790
|
-
|
|
791
1087
|
# Complete Example
|
|
792
1088
|
|
|
793
1089
|
```javascript
|
|
@@ -819,8 +1115,6 @@ client.on("DISCONNECT", () => {
|
|
|
819
1115
|
client.login(process.env.DISCORD_TOKEN);
|
|
820
1116
|
```
|
|
821
1117
|
|
|
822
|
-
---
|
|
823
|
-
|
|
824
1118
|
# Exported API
|
|
825
1119
|
|
|
826
1120
|
SelfJS currently exports:
|
package/package.json
CHANGED
package/self.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @name SelfJS
|
|
3
3
|
* @description Breaking Discord's TOS to bot user accounts.
|
|
4
4
|
* @author Entity
|
|
5
|
-
* @version 4.
|
|
5
|
+
* @version 4.1
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
const EventEmitter = require("events");
|
|
@@ -576,7 +576,9 @@ class Client extends EventEmitter {
|
|
|
576
576
|
* Gets the channels active in the DM list of the user, channels can be both DMs and group chats
|
|
577
577
|
* @returns {Promise<Object>} The list of channels open in the user's DM list
|
|
578
578
|
*/
|
|
579
|
-
getOpenChannels() {
|
|
579
|
+
getOpenChannels() {
|
|
580
|
+
return this.#GET({path: "/users/@me/channels"});
|
|
581
|
+
}
|
|
580
582
|
|
|
581
583
|
/**
|
|
582
584
|
* Closes the current session and disconnects from discord
|
|
@@ -720,6 +722,152 @@ class Client extends EventEmitter {
|
|
|
720
722
|
query: {limit: options.limit, before: options.before}
|
|
721
723
|
});
|
|
722
724
|
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Creates a group DM with certain members
|
|
728
|
+
* @param {Array<String>} recipients A list of user ids to add to the created group
|
|
729
|
+
* @returns {Promise<Object>} The new channel object after creation
|
|
730
|
+
*/
|
|
731
|
+
createGroupDM(recipients) {
|
|
732
|
+
return this.#POST({path: `/users/@me/channels`, body: {recipients}});
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Removes a user from a group dm if the logged in account owns the group
|
|
737
|
+
* @param {Object} options Options specifying which user to remove and from what group
|
|
738
|
+
* @param {String} options.channel_id The id of the group to remove the user from
|
|
739
|
+
* @param {String} options.user_id The id of the user to be removed from the group
|
|
740
|
+
* @returns {Promise<void>} No content returned on success
|
|
741
|
+
*/
|
|
742
|
+
removeFromGroup(options) {
|
|
743
|
+
return this.#DELETE({path: `/channels/${options.channel_id}/recipients/${options.user_id}`});
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Adds a user to a group dm if the logged in account is friends with the user
|
|
748
|
+
* @param {Object} options Options specifying which user to add and to what group
|
|
749
|
+
* @param {String} options.channel_id The id of the group to add the user to
|
|
750
|
+
* @param {String} options.user_id The id of the user to be added to the group
|
|
751
|
+
* @returns {Promise<void>} No content returned on success
|
|
752
|
+
*/
|
|
753
|
+
addToGroup(options) {
|
|
754
|
+
return this.#PUT({path: `/channels/${options.channel_id}/recipients/${options.user_id}`});
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Transfers ownership of a group to another user if that user is in the group
|
|
759
|
+
* @param {Object} options Options specifying which user to give owner and in what group
|
|
760
|
+
* @param {String} options.channel_id The id of the group to be transfered
|
|
761
|
+
* @param {String} options.user_id The id of the user to given ownership of the group
|
|
762
|
+
* @returns {Promise<Object>} The new channel object after the transfer
|
|
763
|
+
*/
|
|
764
|
+
transferGroup(options) {
|
|
765
|
+
return this.#PATCH({
|
|
766
|
+
path: `/channels/${options.channel_id}`,
|
|
767
|
+
body: {owner: options.user_id}
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Leaves a group while optionally not notifying members of that group
|
|
773
|
+
* @param {Object} options Options specifying what group to leave and if the leave should notify
|
|
774
|
+
* @param {String} options.channel_id The id of the group to leave
|
|
775
|
+
* @param {Boolean} [options.silent] If true, the group will not receive a leave notification
|
|
776
|
+
* @returns {Promise<Object>} The new channel object after the group has been left
|
|
777
|
+
*/
|
|
778
|
+
leaveGroup(options) {
|
|
779
|
+
return this.#DELETE({
|
|
780
|
+
path: `/channels/${options.channel_id}`,
|
|
781
|
+
query: {silent: options.silent}
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Shows the typing indicator for other users in a certain channel for 10 seconds
|
|
787
|
+
* Calling this again before the indicator expires resets the timer, while sending a message clears the indicator
|
|
788
|
+
* @param {String} channel_id The id of the channel to start typing in
|
|
789
|
+
* @returns {Promise<void>} No content returned on success
|
|
790
|
+
*/
|
|
791
|
+
startTyping(channel_id) {
|
|
792
|
+
return this.#POST({path: `/channels/${channel_id}/typing`});
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Pins a message to a certain channel
|
|
797
|
+
* @param {Object} options Specifies the message and channel to pin it in
|
|
798
|
+
* @param {String} options.channel_id The id of the channel to pin the message in
|
|
799
|
+
* @param {String} options.message_id The id of the message to pin in the channel
|
|
800
|
+
* @returns {Promise<void>} No content returned on success
|
|
801
|
+
*/
|
|
802
|
+
pinMessage(options) {
|
|
803
|
+
return this.#PUT({path: `/api/v10/channels/${options.channel_id}/pins/${options.message_id}`});
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Unpins a message from a certain channel
|
|
808
|
+
* @param {Object} options Specifies the message and channel to unpin it from
|
|
809
|
+
* @param {String} options.channel_id The id of the channel to unpin the message from
|
|
810
|
+
* @param {String} options.message_id The id of the message to unpin from the channel
|
|
811
|
+
* @returns {Promise<void>} No content returned on success
|
|
812
|
+
*/
|
|
813
|
+
unpinMessage(options) {
|
|
814
|
+
return this.#DELETE({path: `/api/v10/channels/${options.channel_id}/pins/${options.message_id}`});
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Gets the current representation of a channel via its id
|
|
819
|
+
* Channels can be DMs, group DMs, server text, or server voice channels
|
|
820
|
+
* @param {String} channel_id
|
|
821
|
+
* @returns {Promise<Object>} The current channel object
|
|
822
|
+
*/
|
|
823
|
+
getChannelObject(channel_id) {
|
|
824
|
+
return this.#GET({path: `/channels/${channel_id}`});
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* Gets the channel object for DMs with a certain user
|
|
829
|
+
* Getting the channel object also opens the channel in the active DM list
|
|
830
|
+
* @param {String} user_id The id of the user to get the DM channel of
|
|
831
|
+
* @returns {Promise<Object>} The DM channel object
|
|
832
|
+
*/
|
|
833
|
+
getDMChannel(user_id) {
|
|
834
|
+
return this.#POST({path: "/users/@me/channels", body: {recipients: [user_id]}});
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Closes and hides the DM channel for a certain user from the active list
|
|
839
|
+
* @param {String} user_id The id of the user to close the DM channel of
|
|
840
|
+
* @returns {Promise<Object>} Returns the channel after closing on success
|
|
841
|
+
*/
|
|
842
|
+
async closeDMChannel(user_id) {
|
|
843
|
+
const channel = await this.getDMChannel(user_id);
|
|
844
|
+
if(!("id" in channel)) return null;
|
|
845
|
+
return this.#DELETE({path: `/channels/${channel.id}`});
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* Get a user's profile if one of the following is true:
|
|
850
|
+
* The client shares a server with the user, is friends with the user
|
|
851
|
+
* The user sent a friend request to the client, or the user is a bot
|
|
852
|
+
* @param {Object} options The options specifying what the response should contain
|
|
853
|
+
* @param {String} options.user_id The id of the user to request the profile of
|
|
854
|
+
* @param {Boolean} [options.with_mutual_servers] If true or absent, include mutual servers in the response
|
|
855
|
+
* @param {Boolean} [options.with_mutual_friends] If true, include mutual friends in the response
|
|
856
|
+
* @param {Boolean} [options.with_mutual_friends_count] If true, include the number of mutual friends in the response
|
|
857
|
+
* @param {String} [options.guild_id] If present respond with the server profile for this guild
|
|
858
|
+
* @returns {Promise<Object>} The user's profile on success, 404 error if no conditions were met
|
|
859
|
+
*/
|
|
860
|
+
getUserProfile(options) {
|
|
861
|
+
return this.#GET({
|
|
862
|
+
path: `/users/${options.user_id}/profile`,
|
|
863
|
+
query: {
|
|
864
|
+
guild_id: options.guild_id,
|
|
865
|
+
with_mutual_guilds: options.with_mutual_servers,
|
|
866
|
+
with_mutual_friends: options.with_mutual_friends,
|
|
867
|
+
with_mutual_friends_count: options.with_mutual_friends_count
|
|
868
|
+
}
|
|
869
|
+
});
|
|
870
|
+
}
|
|
723
871
|
}
|
|
724
872
|
|
|
725
873
|
module.exports = {
|