@imaentity/selfjs 4.0.0 → 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/README.md +12 -10
- package/docs.md +1142 -848
- package/package.json +1 -1
- package/self.js +151 -3
package/docs.md
CHANGED
|
@@ -1,848 +1,1142 @@
|
|
|
1
|
-
# SelfJS Documentation
|
|
2
|
-
Welcome To SelfJS Documentation
|
|
3
|
-
|
|
4
|
-
> [!WARNING]
|
|
5
|
-
> These docs might not be up to date or 100% correct, Self is always being added to.
|
|
6
|
-
> If a descrepancy is found perfer the JSdoc included with the self.js file
|
|
7
|
-
|
|
8
|
-
## Installation
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
npm install @imaentity/selfjs
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
## Import
|
|
15
|
-
|
|
16
|
-
```javascript
|
|
17
|
-
const self = require("@imaentity/selfjs");
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Status.
|
|
30
|
-
Status.
|
|
31
|
-
Status.
|
|
32
|
-
Status.
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
console.log(
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
## `client.
|
|
237
|
-
|
|
238
|
-
The
|
|
239
|
-
|
|
240
|
-
```javascript
|
|
241
|
-
console.log(client.
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
## `client.token`
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
```javascript
|
|
319
|
-
client.on("MESSAGE_CREATE", message => {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
client.
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
```
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
```
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
```
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
|
559
|
-
|
|
|
560
|
-
| `options.
|
|
561
|
-
| `options.
|
|
562
|
-
| `options.
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
```
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
```
|
|
613
|
-
|
|
614
|
-
###
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
```
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
```
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
```javascript
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
```
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
|
688
|
-
|
|
|
689
|
-
| `options.
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
###
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
client.
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
1
|
+
# SelfJS Documentation
|
|
2
|
+
Welcome To SelfJS Documentation
|
|
3
|
+
|
|
4
|
+
> [!WARNING]
|
|
5
|
+
> These docs might not be up to date or 100% correct, Self is always being added to.
|
|
6
|
+
> If a descrepancy is found perfer the JSdoc included with the self.js file
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @imaentity/selfjs
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Import
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
const self = require("@imaentity/selfjs");
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
# Constants
|
|
21
|
+
|
|
22
|
+
## `Status`
|
|
23
|
+
|
|
24
|
+
Contains the activity types used by Discord.
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
Status.PLAYING // 0
|
|
28
|
+
Status.STREAMING // 1
|
|
29
|
+
Status.LISTENING // 2
|
|
30
|
+
Status.WATCHING // 3
|
|
31
|
+
Status.CUSTOM_STATUS // 4
|
|
32
|
+
Status.COMPETING // 5
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
# Functions
|
|
36
|
+
|
|
37
|
+
## `validateToken(token)`
|
|
38
|
+
|
|
39
|
+
Checks whether a Discord token is valid without creating a persistent `Client`.
|
|
40
|
+
|
|
41
|
+
Returns the user's Discord user object if valid, or `null` if the token is invalid.
|
|
42
|
+
|
|
43
|
+
### Parameters
|
|
44
|
+
|
|
45
|
+
| Name | Type | Description |
|
|
46
|
+
| ------- | -------- | ------------------------------ |
|
|
47
|
+
| `token` | `String` | The Discord token to validate. |
|
|
48
|
+
|
|
49
|
+
### Returns
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
Promise<Object | null>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Example
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
const user = await self.validateToken(token);
|
|
59
|
+
|
|
60
|
+
if(user)
|
|
61
|
+
console.log(`Logged in as ${user.username}`);
|
|
62
|
+
else
|
|
63
|
+
console.log("Invalid token");
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## `createToken(options)`
|
|
67
|
+
|
|
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.
|
|
70
|
+
If MFA is required, the returned object contains the available MFA methods and a `confirmMFA()` function.
|
|
71
|
+
|
|
72
|
+
### Parameters
|
|
73
|
+
|
|
74
|
+
| Name | Type | Description |
|
|
75
|
+
| ------------------ | -------- | ----------------- |
|
|
76
|
+
| `options` | `Object` | Login options. |
|
|
77
|
+
| `options.email` | `String` | Account email. |
|
|
78
|
+
| `options.password` | `String` | Account password. |
|
|
79
|
+
|
|
80
|
+
### Returns
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
Promise<Object | null>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Successful login
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
{
|
|
90
|
+
token: String,
|
|
91
|
+
user_id: String,
|
|
92
|
+
mfaRequired: false
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### MFA login
|
|
97
|
+
|
|
98
|
+
```javascript
|
|
99
|
+
{
|
|
100
|
+
user_id: String,
|
|
101
|
+
mfaRequired: true,
|
|
102
|
+
mfaMethods: Array<String>,
|
|
103
|
+
confirmMFA: Function
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Example
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
const login = await self.createToken({
|
|
111
|
+
email: "discord@example.com",
|
|
112
|
+
password: "password"
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if(!login)
|
|
116
|
+
throw new Error("Login failed");
|
|
117
|
+
|
|
118
|
+
if(!login.mfaRequired) {
|
|
119
|
+
console.log(login.token);
|
|
120
|
+
} else {
|
|
121
|
+
console.log("MFA methods:", login.mfaMethods);
|
|
122
|
+
|
|
123
|
+
const result = await login.confirmMFA("totp", {
|
|
124
|
+
code: "123456"
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
console.log(result);
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
> [!NOTE]
|
|
132
|
+
> SMS MFA is currently unsupported.
|
|
133
|
+
|
|
134
|
+
## `snowflakeToUTC(snowflake)`
|
|
135
|
+
|
|
136
|
+
Converts a Discord snowflake into a UTC timestamp.
|
|
137
|
+
The returned timestamp is in milliseconds since Unix epoch.
|
|
138
|
+
|
|
139
|
+
### Parameters
|
|
140
|
+
|
|
141
|
+
| Name | Type | Description |
|
|
142
|
+
| ----------- | -------- | ------------------ |
|
|
143
|
+
| `snowflake` | `String` | Discord snowflake. |
|
|
144
|
+
|
|
145
|
+
### Returns
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
Number
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Example
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
const timestamp = self.snowflakeToUTC("1329029486758592595");
|
|
155
|
+
|
|
156
|
+
console.log(new Date(timestamp));
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## `UTCToSnowflake(timestamp)`
|
|
160
|
+
|
|
161
|
+
Converts a UTC timestamp into a Discord snowflake.
|
|
162
|
+
The generated snowflake only contains the timestamp portion. Worker ID, process ID, and sequence values are zero.
|
|
163
|
+
|
|
164
|
+
### Parameters
|
|
165
|
+
|
|
166
|
+
| Name | Type | Description |
|
|
167
|
+
| ----------- | -------- | ------------------------------ |
|
|
168
|
+
| `timestamp` | `Number` | UTC timestamp in milliseconds. |
|
|
169
|
+
|
|
170
|
+
### Returns
|
|
171
|
+
|
|
172
|
+
```javascript
|
|
173
|
+
String
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Example
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
const snowflake = self.UTCToSnowflake(Date.now());
|
|
180
|
+
|
|
181
|
+
console.log(snowflake);
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
# Client
|
|
185
|
+
|
|
186
|
+
`Client` provides an interface for connecting to Discord and interacting with the account.
|
|
187
|
+
|
|
188
|
+
## Creating a client
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
const client = new self.Client();
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Options
|
|
195
|
+
|
|
196
|
+
```javascript
|
|
197
|
+
const client = new self.Client({
|
|
198
|
+
properties: {
|
|
199
|
+
os: process.platform,
|
|
200
|
+
browser: "SelfJS",
|
|
201
|
+
device: "NodeJS"
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
debugLogs: true,
|
|
205
|
+
|
|
206
|
+
intents: 0
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
| Option | Type | Default | Description |
|
|
211
|
+
| ------------ | --------- | ------------- | --------------------------------------- |
|
|
212
|
+
| `properties` | `Object` | `LOGIN_PROPS` | Gateway identify properties. |
|
|
213
|
+
| `debugLogs` | `Boolean` | `true` | Enables SelfJS debug logging. |
|
|
214
|
+
| `intents` | `Number` | `null` | Gateway intents, used for bot accounts. |
|
|
215
|
+
|
|
216
|
+
# Properties
|
|
217
|
+
|
|
218
|
+
## `client.user`
|
|
219
|
+
|
|
220
|
+
The user object belonging to the logged-in account.
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
console.log(client.user);
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
This is populated after the `READY` event.
|
|
227
|
+
|
|
228
|
+
## `client.token`
|
|
229
|
+
|
|
230
|
+
The token currently being used by the client.
|
|
231
|
+
|
|
232
|
+
```javascript
|
|
233
|
+
console.log(client.token);
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## `client.latency`
|
|
237
|
+
|
|
238
|
+
The time between sending a heartbeat and receiving its acknowledgement.
|
|
239
|
+
|
|
240
|
+
```javascript
|
|
241
|
+
console.log(client.latency);
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
The value is in milliseconds.
|
|
245
|
+
|
|
246
|
+
# Login
|
|
247
|
+
|
|
248
|
+
## `client.login(token)`
|
|
249
|
+
|
|
250
|
+
Connects the client to the Discord Gateway using the provided token.
|
|
251
|
+
|
|
252
|
+
### Parameters
|
|
253
|
+
|
|
254
|
+
| Name | Type | Description |
|
|
255
|
+
| ------- | -------- | ---------------------- |
|
|
256
|
+
| `token` | `String` | Discord account token. |
|
|
257
|
+
|
|
258
|
+
### Example
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
client.login(token);
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Once connected, events can be received using `client.on()`.
|
|
265
|
+
|
|
266
|
+
# Events
|
|
267
|
+
|
|
268
|
+
`Client` extends Node.js `EventEmitter`, so events can be listened to using `.on()`.
|
|
269
|
+
|
|
270
|
+
```javascript
|
|
271
|
+
client.on("MESSAGE_CREATE", message => {
|
|
272
|
+
console.log(message.content);
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## `READY`
|
|
277
|
+
|
|
278
|
+
Emitted when the client successfully logs in.
|
|
279
|
+
|
|
280
|
+
```javascript
|
|
281
|
+
client.on("READY", data => {
|
|
282
|
+
console.log("Logged in as:", data.user.username);
|
|
283
|
+
});
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## `MESSAGE_CREATE`
|
|
287
|
+
|
|
288
|
+
Emitted when a message is received.
|
|
289
|
+
|
|
290
|
+
```javascript
|
|
291
|
+
client.on("MESSAGE_CREATE", message => {
|
|
292
|
+
console.log(message.content);
|
|
293
|
+
});
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
The message object also receives:
|
|
297
|
+
|
|
298
|
+
```javascript
|
|
299
|
+
message.author.self
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
which is `true` when the message was sent by the current account.
|
|
303
|
+
|
|
304
|
+
### Preventing automatic acknowledgement
|
|
305
|
+
|
|
306
|
+
Messages are automatically acknowledged unless they were sent by the current account.
|
|
307
|
+
|
|
308
|
+
Call:
|
|
309
|
+
|
|
310
|
+
```javascript
|
|
311
|
+
message.preventACK();
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
to prevent the automatic acknowledgement.
|
|
315
|
+
|
|
316
|
+
Example:
|
|
317
|
+
|
|
318
|
+
```javascript
|
|
319
|
+
client.on("MESSAGE_CREATE", message => {
|
|
320
|
+
if(message.content === "keep this unread")
|
|
321
|
+
message.preventACK();
|
|
322
|
+
});
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## `DISCONNECT`
|
|
326
|
+
|
|
327
|
+
Emitted when the Gateway connection closes.
|
|
328
|
+
|
|
329
|
+
```javascript
|
|
330
|
+
client.on("DISCONNECT", () => {
|
|
331
|
+
console.log("Disconnected");
|
|
332
|
+
});
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## `INVALID_SESSION`
|
|
336
|
+
|
|
337
|
+
Emitted when Discord invalidates the current session and it cannot be resumed.
|
|
338
|
+
|
|
339
|
+
```javascript
|
|
340
|
+
client.on("INVALID_SESSION", () => {
|
|
341
|
+
console.log("Session invalidated");
|
|
342
|
+
});
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
# Messages
|
|
346
|
+
|
|
347
|
+
## `client.sendMessage(message)`
|
|
348
|
+
|
|
349
|
+
Sends a message to a channel.
|
|
350
|
+
|
|
351
|
+
### Parameters
|
|
352
|
+
|
|
353
|
+
| Name | Type | Description |
|
|
354
|
+
| --------------------------- | --------------- | -------------------------- |
|
|
355
|
+
| `message` | `Object` | Message data. |
|
|
356
|
+
| `message.channel_id` | `String` | Channel ID. |
|
|
357
|
+
| `message.content` | `String` | Message content. |
|
|
358
|
+
| `message.files` | `Array<Object>` | Optional file attachments. |
|
|
359
|
+
| `message.message_reference` | `Object` | Optional reply reference. |
|
|
360
|
+
|
|
361
|
+
### Reply reference
|
|
362
|
+
|
|
363
|
+
```javascript
|
|
364
|
+
{
|
|
365
|
+
id: "123456789",
|
|
366
|
+
channel_id: "987654321"
|
|
367
|
+
}
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### File
|
|
371
|
+
|
|
372
|
+
A file object can contain:
|
|
373
|
+
|
|
374
|
+
```javascript
|
|
375
|
+
{
|
|
376
|
+
filename: "image.png",
|
|
377
|
+
data: Buffer,
|
|
378
|
+
spoiled: false
|
|
379
|
+
}
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Example
|
|
383
|
+
|
|
384
|
+
```javascript
|
|
385
|
+
await client.sendMessage({
|
|
386
|
+
channel_id: "123456789",
|
|
387
|
+
content: "Hello!"
|
|
388
|
+
});
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### Example with a file
|
|
392
|
+
|
|
393
|
+
```javascript
|
|
394
|
+
await client.sendMessage({
|
|
395
|
+
channel_id: "123456789",
|
|
396
|
+
content: "Here is a file",
|
|
397
|
+
files: [{
|
|
398
|
+
filename: "image.png",
|
|
399
|
+
data: require("fs").readFileSync("image.png"),
|
|
400
|
+
spoiled: false
|
|
401
|
+
}]
|
|
402
|
+
});
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
## `client.editMessage(message)`
|
|
406
|
+
|
|
407
|
+
Edits an existing message.
|
|
408
|
+
|
|
409
|
+
### Parameters
|
|
410
|
+
|
|
411
|
+
| Name | Type | Description |
|
|
412
|
+
| -------------------- | --------------- | ------------------------- |
|
|
413
|
+
| `message` | `Object` | Message data. |
|
|
414
|
+
| `message.id` | `String` | Message ID. |
|
|
415
|
+
| `message.channel_id` | `String` | Channel ID. |
|
|
416
|
+
| `message.content` | `String` | New message content. |
|
|
417
|
+
| `message.files` | `Array<Object>` | Optional new attachments. |
|
|
418
|
+
|
|
419
|
+
### Example
|
|
420
|
+
|
|
421
|
+
```javascript
|
|
422
|
+
await client.editMessage({
|
|
423
|
+
channel_id: "123456789",
|
|
424
|
+
id: "987654321",
|
|
425
|
+
content: "Edited message"
|
|
426
|
+
});
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## `client.getMessages(options)`
|
|
430
|
+
|
|
431
|
+
Gets recent messages from a channel.
|
|
432
|
+
|
|
433
|
+
### Parameters
|
|
434
|
+
|
|
435
|
+
| Name | Type | Description |
|
|
436
|
+
| -------------------- | -------- | -------------------------------------------- |
|
|
437
|
+
| `options.channel_id` | `String` | Channel ID. |
|
|
438
|
+
| `options.limit` | `Number` | Maximum number of messages. |
|
|
439
|
+
| `options.before` | `String` | Only return messages before this message ID. |
|
|
440
|
+
|
|
441
|
+
### Returns
|
|
442
|
+
|
|
443
|
+
```javascript
|
|
444
|
+
Promise<Array>
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
Messages are returned from newest to oldest.
|
|
448
|
+
|
|
449
|
+
### Example
|
|
450
|
+
|
|
451
|
+
```javascript
|
|
452
|
+
const messages = await client.getMessages({
|
|
453
|
+
channel_id: "123456789",
|
|
454
|
+
limit: 25
|
|
455
|
+
});
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
## `client.ackMessage(message)`
|
|
459
|
+
|
|
460
|
+
Acknowledges a message, removing its unread notification.
|
|
461
|
+
|
|
462
|
+
### Parameters
|
|
463
|
+
|
|
464
|
+
| Name | Type | Description |
|
|
465
|
+
| -------------------- | -------- | ----------- |
|
|
466
|
+
| `message.channel_id` | `String` | Channel ID. |
|
|
467
|
+
| `message.id` | `String` | Message ID. |
|
|
468
|
+
|
|
469
|
+
### Returns
|
|
470
|
+
|
|
471
|
+
```javascript
|
|
472
|
+
Promise<Object>
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
### Example
|
|
476
|
+
|
|
477
|
+
```javascript
|
|
478
|
+
await client.ackMessage({
|
|
479
|
+
channel_id: "123456789",
|
|
480
|
+
id: "987654321"
|
|
481
|
+
});
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
# Reactions
|
|
485
|
+
|
|
486
|
+
## `client.addReaction(options)`
|
|
487
|
+
|
|
488
|
+
Adds a reaction to a message.
|
|
489
|
+
|
|
490
|
+
### Parameters
|
|
491
|
+
|
|
492
|
+
| Name | Type | Description |
|
|
493
|
+
| -------------------- | -------- | -------------------- |
|
|
494
|
+
| `options.channel_id` | `String` | Channel ID. |
|
|
495
|
+
| `options.message_id` | `String` | Message ID. |
|
|
496
|
+
| `options.emoji` | `String` | Emoji to react with. |
|
|
497
|
+
|
|
498
|
+
### Example
|
|
499
|
+
|
|
500
|
+
```javascript
|
|
501
|
+
await client.addReaction({
|
|
502
|
+
channel_id: "123456789",
|
|
503
|
+
message_id: "987654321",
|
|
504
|
+
emoji: "👍"
|
|
505
|
+
});
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
## `client.removeReaction(options)`
|
|
509
|
+
|
|
510
|
+
Removes the client's reaction from a message.
|
|
511
|
+
|
|
512
|
+
### Parameters
|
|
513
|
+
|
|
514
|
+
| Name | Type | Description |
|
|
515
|
+
| -------------------- | -------- | ---------------- |
|
|
516
|
+
| `options.channel_id` | `String` | Channel ID. |
|
|
517
|
+
| `options.message_id` | `String` | Message ID. |
|
|
518
|
+
| `options.emoji` | `String` | Emoji to remove. |
|
|
519
|
+
|
|
520
|
+
### Example
|
|
521
|
+
|
|
522
|
+
```javascript
|
|
523
|
+
await client.removeReaction({
|
|
524
|
+
channel_id: "123456789",
|
|
525
|
+
message_id: "987654321",
|
|
526
|
+
emoji: "👍"
|
|
527
|
+
});
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
# Channels
|
|
531
|
+
|
|
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
|
+
```
|
|
549
|
+
|
|
550
|
+
## `client.search(options)`
|
|
551
|
+
|
|
552
|
+
Searches for messages in a channel.
|
|
553
|
+
|
|
554
|
+
### Parameters
|
|
555
|
+
|
|
556
|
+
| Name | Type | Description |
|
|
557
|
+
| ---------------------- | ------------------------------- | ---------------------------------------- |
|
|
558
|
+
| `options.channel_id` | `String` | Channel ID. |
|
|
559
|
+
| `options.content` | `String` | Search message content. |
|
|
560
|
+
| `options.authors` | `Array<String>` | Filter by author IDs. |
|
|
561
|
+
| `options.mentions` | `Array<String>` | Filter by mentioned user IDs. |
|
|
562
|
+
| `options.contentTypes` | `Array<String>` | Filter by content type. |
|
|
563
|
+
| `options.pinned` | `Boolean` | Only return pinned messages. |
|
|
564
|
+
| `options.authorTypes` | `Array<String>` | Filter by author type. |
|
|
565
|
+
| `options.sort` | `"new" \| "old" \| "relevance"` | Search sorting mode. |
|
|
566
|
+
| `options.offset` | `Number` | Number of results to skip. |
|
|
567
|
+
| `options.after` | `Number` | Only messages after this UTC timestamp. |
|
|
568
|
+
| `options.before` | `Number` | Only messages before this UTC timestamp. |
|
|
569
|
+
|
|
570
|
+
### Content types
|
|
571
|
+
|
|
572
|
+
Valid `contentTypes` values include:
|
|
573
|
+
|
|
574
|
+
```text
|
|
575
|
+
image
|
|
576
|
+
video
|
|
577
|
+
link
|
|
578
|
+
file
|
|
579
|
+
embed
|
|
580
|
+
sound
|
|
581
|
+
poll
|
|
582
|
+
sticker
|
|
583
|
+
snapshot
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
### Author types
|
|
587
|
+
|
|
588
|
+
Valid `authorTypes` values include:
|
|
589
|
+
|
|
590
|
+
```text
|
|
591
|
+
user
|
|
592
|
+
bot
|
|
593
|
+
webhook
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
### Sorting
|
|
597
|
+
|
|
598
|
+
```javascript
|
|
599
|
+
sort: "new"
|
|
600
|
+
sort: "old"
|
|
601
|
+
sort: "relevance"
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
### Example
|
|
605
|
+
|
|
606
|
+
```javascript
|
|
607
|
+
const results = await client.search({
|
|
608
|
+
channel_id: "123456789",
|
|
609
|
+
content: "hello",
|
|
610
|
+
sort: "relevance"
|
|
611
|
+
});
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
### Date filtering
|
|
615
|
+
|
|
616
|
+
`after` and `before` use UTC timestamps in milliseconds.
|
|
617
|
+
|
|
618
|
+
```javascript
|
|
619
|
+
const results = await client.search({
|
|
620
|
+
channel_id: "123456789",
|
|
621
|
+
after: Date.now() - 86400000
|
|
622
|
+
});
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
## `client.createGroupDM(recipients)`
|
|
627
|
+
|
|
628
|
+
Creates a group DM with the specified users.
|
|
629
|
+
|
|
630
|
+
### Parameters
|
|
631
|
+
|
|
632
|
+
| Name | Type | Description |
|
|
633
|
+
| ------------ | --------------- | ----------------------------- |
|
|
634
|
+
| `recipients` | `Array<String>` | User IDs to add to the group. |
|
|
635
|
+
|
|
636
|
+
### Returns
|
|
637
|
+
|
|
638
|
+
```javascript
|
|
639
|
+
Promise<Object>
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
The new channel object.
|
|
643
|
+
|
|
644
|
+
### Example
|
|
645
|
+
|
|
646
|
+
```javascript
|
|
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
|
+
});
|
|
705
|
+
```
|
|
706
|
+
|
|
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
|
+
```
|
|
979
|
+
|
|
980
|
+
# Status
|
|
981
|
+
|
|
982
|
+
## `client.setStatus(options)`
|
|
983
|
+
|
|
984
|
+
Sets the account's status and activities.
|
|
985
|
+
|
|
986
|
+
### Parameters
|
|
987
|
+
|
|
988
|
+
| Name | Type | Description |
|
|
989
|
+
| -------------------- | -------------------------------------------- | ---------------------- |
|
|
990
|
+
| `options.status` | `"online" \| "idle" \| "dnd" \| "invisible"` | Account status. |
|
|
991
|
+
| `options.activities` | `Array<Object>` | Activities to display. |
|
|
992
|
+
|
|
993
|
+
Activity objects contain:
|
|
994
|
+
|
|
995
|
+
```javascript
|
|
996
|
+
{
|
|
997
|
+
type: Number,
|
|
998
|
+
name: String
|
|
999
|
+
}
|
|
1000
|
+
```
|
|
1001
|
+
|
|
1002
|
+
### Example
|
|
1003
|
+
|
|
1004
|
+
```javascript
|
|
1005
|
+
client.setStatus({
|
|
1006
|
+
status: "dnd",
|
|
1007
|
+
|
|
1008
|
+
activities: [{
|
|
1009
|
+
name: "with the Discord API",
|
|
1010
|
+
type: Status.PLAYING
|
|
1011
|
+
}]
|
|
1012
|
+
});
|
|
1013
|
+
```
|
|
1014
|
+
|
|
1015
|
+
### Custom status
|
|
1016
|
+
|
|
1017
|
+
```javascript
|
|
1018
|
+
client.setStatus({
|
|
1019
|
+
status: "online",
|
|
1020
|
+
|
|
1021
|
+
activities: [{
|
|
1022
|
+
name: "my custom status",
|
|
1023
|
+
type: Status.CUSTOM_STATUS
|
|
1024
|
+
}]
|
|
1025
|
+
});
|
|
1026
|
+
```
|
|
1027
|
+
|
|
1028
|
+
### Streaming
|
|
1029
|
+
|
|
1030
|
+
Streaming activities automatically receive the activity's name as `details`.
|
|
1031
|
+
|
|
1032
|
+
```javascript
|
|
1033
|
+
client.setStatus({
|
|
1034
|
+
status: "online",
|
|
1035
|
+
|
|
1036
|
+
activities: [{
|
|
1037
|
+
name: "Minecraft",
|
|
1038
|
+
type: Status.STREAMING
|
|
1039
|
+
}]
|
|
1040
|
+
});
|
|
1041
|
+
```
|
|
1042
|
+
|
|
1043
|
+
# Authentication
|
|
1044
|
+
|
|
1045
|
+
## `client.logout()`
|
|
1046
|
+
|
|
1047
|
+
Logs out the current account and closes the Gateway connection.
|
|
1048
|
+
|
|
1049
|
+
### Returns
|
|
1050
|
+
|
|
1051
|
+
```javascript
|
|
1052
|
+
Promise<Object>
|
|
1053
|
+
```
|
|
1054
|
+
|
|
1055
|
+
### Example
|
|
1056
|
+
|
|
1057
|
+
```javascript
|
|
1058
|
+
await client.logout();
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
# Connection
|
|
1062
|
+
|
|
1063
|
+
## `client.disconnect(code)`
|
|
1064
|
+
|
|
1065
|
+
Closes the current Gateway session.
|
|
1066
|
+
|
|
1067
|
+
After disconnecting, the client will no longer receive Gateway events. Call `login()` again to create a new session.
|
|
1068
|
+
|
|
1069
|
+
### Parameters
|
|
1070
|
+
|
|
1071
|
+
| Name | Type | Default | Description |
|
|
1072
|
+
| ------ | -------- | ------- | --------------------- |
|
|
1073
|
+
| `code` | `Number` | `1000` | WebSocket close code. |
|
|
1074
|
+
|
|
1075
|
+
### Example
|
|
1076
|
+
|
|
1077
|
+
```javascript
|
|
1078
|
+
client.disconnect();
|
|
1079
|
+
```
|
|
1080
|
+
|
|
1081
|
+
Or with a specific close code:
|
|
1082
|
+
|
|
1083
|
+
```javascript
|
|
1084
|
+
client.disconnect(1000);
|
|
1085
|
+
```
|
|
1086
|
+
|
|
1087
|
+
# Complete Example
|
|
1088
|
+
|
|
1089
|
+
```javascript
|
|
1090
|
+
const self = require("@imaentity/selfjs");
|
|
1091
|
+
|
|
1092
|
+
const client = new self.Client({
|
|
1093
|
+
debugLogs: true
|
|
1094
|
+
});
|
|
1095
|
+
|
|
1096
|
+
client.on("READY", data => {
|
|
1097
|
+
console.log(`Logged in as ${data.user.username}`);
|
|
1098
|
+
});
|
|
1099
|
+
|
|
1100
|
+
client.on("MESSAGE_CREATE", async message => {
|
|
1101
|
+
console.log(`${message.author.username}: ${message.content}`);
|
|
1102
|
+
|
|
1103
|
+
if(message.content === "!hello") {
|
|
1104
|
+
await client.sendMessage({
|
|
1105
|
+
channel_id: message.channel_id,
|
|
1106
|
+
content: "Hello!"
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
});
|
|
1110
|
+
|
|
1111
|
+
client.on("DISCONNECT", () => {
|
|
1112
|
+
console.log("Disconnected");
|
|
1113
|
+
});
|
|
1114
|
+
|
|
1115
|
+
client.login(process.env.DISCORD_TOKEN);
|
|
1116
|
+
```
|
|
1117
|
+
|
|
1118
|
+
# Exported API
|
|
1119
|
+
|
|
1120
|
+
SelfJS currently exports:
|
|
1121
|
+
|
|
1122
|
+
```javascript
|
|
1123
|
+
module.exports = {
|
|
1124
|
+
Status,
|
|
1125
|
+
validateToken,
|
|
1126
|
+
createToken,
|
|
1127
|
+
UTCToSnowflake,
|
|
1128
|
+
snowflakeToUTC,
|
|
1129
|
+
Client
|
|
1130
|
+
};
|
|
1131
|
+
```
|
|
1132
|
+
|
|
1133
|
+
So the following are available:
|
|
1134
|
+
|
|
1135
|
+
```javascript
|
|
1136
|
+
self.Status
|
|
1137
|
+
self.validateToken
|
|
1138
|
+
self.createToken
|
|
1139
|
+
self.UTCToSnowflake
|
|
1140
|
+
self.snowflakeToUTC
|
|
1141
|
+
self.Client
|
|
1142
|
+
```
|