mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-28 06:20:10 +00:00
Compare commits
875 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0bc4d7ff0 | ||
|
|
2bf09703c1 | ||
|
|
dcc556c311 | ||
|
|
14aea12900 | ||
|
|
e6f48d849f | ||
|
|
933d2c5eb7 | ||
|
|
bbda3c4beb | ||
|
|
dce8fc7b9d | ||
|
|
44bbfa5c46 | ||
|
|
4a64662a7d | ||
|
|
6342430073 | ||
|
|
297a9118e7 | ||
|
|
fff887b2f4 | ||
|
|
d9456a1a76 | ||
|
|
cd4029218f | ||
|
|
75b48d8d0f | ||
|
|
de3c86f804 | ||
|
|
0266f28096 | ||
|
|
779e14ef61 | ||
|
|
4c8dc4cda6 | ||
|
|
49d3c0bf87 | ||
|
|
3c17939fd5 | ||
|
|
2a3e819fcf | ||
|
|
006edca410 | ||
|
|
91740ecc30 | ||
|
|
2985e5380f | ||
|
|
0062aa6f72 | ||
|
|
ea8d77ea62 | ||
|
|
cd393fd421 | ||
|
|
efc20ff669 | ||
|
|
5f1def3793 | ||
|
|
47d2ef3e40 | ||
|
|
f13d27ca2e | ||
|
|
570fba33d3 | ||
|
|
94bb953bf1 | ||
|
|
917e71a9ee | ||
|
|
394d48649f | ||
|
|
d87299ba20 | ||
|
|
d14a6bfe1d | ||
|
|
68c059165b | ||
|
|
d1d740c1a5 | ||
|
|
ed0f605b23 | ||
|
|
b2e23ca03c | ||
|
|
0d765f53d2 | ||
|
|
622f398f4b | ||
|
|
909c87353e | ||
|
|
ceae5960ed | ||
|
|
60ace9a2d4 | ||
|
|
9e6a627a13 | ||
|
|
2b61fb5b3c | ||
|
|
cd1aefb46c | ||
|
|
3bff08acf7 | ||
|
|
cfde127072 | ||
|
|
1200bba7bc | ||
|
|
52817fc414 | ||
|
|
3725dcafc0 | ||
|
|
a0974fdbbb | ||
|
|
d5e28c2298 | ||
|
|
7787a7695a | ||
|
|
06644770c8 | ||
|
|
913c9fa176 | ||
|
|
a56ba097dc | ||
|
|
f473f43d08 | ||
|
|
b4afcf8236 | ||
|
|
4241febe24 | ||
|
|
5b4efd13c9 | ||
|
|
dd3a79eead | ||
|
|
b639b6c653 | ||
|
|
3eb41405f4 | ||
|
|
a6d4035176 | ||
|
|
5be471b47d | ||
|
|
ae6200e58e | ||
|
|
6e3236ab64 | ||
|
|
5b0621fb3a | ||
|
|
90c2e072bf | ||
|
|
00d5ceebf7 | ||
|
|
6b2098f7c7 | ||
|
|
09471be30e | ||
|
|
61db5f7618 | ||
|
|
a72b5a355e | ||
|
|
3c7c82292a | ||
|
|
35fa3b3103 | ||
|
|
15aea68946 | ||
|
|
7e0618f17a | ||
|
|
6e0ea020c0 | ||
|
|
2c452dffb8 | ||
|
|
e2e4f6518b | ||
|
|
626ff85ae7 | ||
|
|
7c540764f0 | ||
|
|
774f5b77ec | ||
|
|
bb56f17760 | ||
|
|
74fc23b3de | ||
|
|
93e0239c80 | ||
|
|
60028251f7 | ||
|
|
00c2bf81cd | ||
|
|
24931d713b | ||
|
|
bb5e648f3d | ||
|
|
a25e16599a | ||
|
|
331a9d3ffc | ||
|
|
77c72e625f | ||
|
|
434e330754 | ||
|
|
198a5c490d | ||
|
|
2a07055cc0 | ||
|
|
00bae4fe6b | ||
|
|
65ae06429d | ||
|
|
82daee576a | ||
|
|
8b52d06ca9 | ||
|
|
bf221f2bef | ||
|
|
797727ab6e | ||
|
|
ee3cdc81dd | ||
|
|
d2757cf899 | ||
|
|
dbb59ba1b2 | ||
|
|
2675b0866c | ||
|
|
cc5f1ce75e | ||
|
|
5f710ae559 | ||
|
|
40b127ee1e | ||
|
|
d310e4fc28 | ||
|
|
6b85f900fa | ||
|
|
105a194546 | ||
|
|
f44bfc47c7 | ||
|
|
1009ce169b | ||
|
|
a69e2f7904 | ||
|
|
4beb64769c | ||
|
|
e000af5c98 | ||
|
|
42a0313034 | ||
|
|
be5c0eff34 | ||
|
|
19b242ac10 | ||
|
|
4f1f32f2a5 | ||
|
|
68725476b3 | ||
|
|
26ba0e1036 | ||
|
|
f060a3fcd7 | ||
|
|
5e433b5995 | ||
|
|
9679b90872 | ||
|
|
30a58dc801 | ||
|
|
b22272f860 | ||
|
|
2f1cc1fc27 | ||
|
|
4886ae23ab | ||
|
|
4f8ca2936a | ||
|
|
690c121aa9 | ||
|
|
c8ca7bfd2c | ||
|
|
870a0de53c | ||
|
|
5e706941fc | ||
|
|
cd47a524af | ||
|
|
328501bd8e | ||
|
|
07017a9699 | ||
|
|
85865058ed | ||
|
|
1e90be8f7a | ||
|
|
5addcd15d8 | ||
|
|
02f55f0971 | ||
|
|
8ccfd6e07b | ||
|
|
54d6a3a070 | ||
|
|
76888e6c1b | ||
|
|
77784aca43 | ||
|
|
8ea04b295d | ||
|
|
63ce065fc3 | ||
|
|
9f039a8679 | ||
|
|
c40c0f934a | ||
|
|
f293132345 | ||
|
|
4d53d0fd11 | ||
|
|
366f3c910a | ||
|
|
ef5ba05996 | ||
|
|
de384047b3 | ||
|
|
5ca97c9351 | ||
|
|
f200f14a40 | ||
|
|
8db6df3d1e | ||
|
|
576eee8de2 | ||
|
|
4206e35b23 | ||
|
|
60148c6a78 | ||
|
|
a9e7ebd94f | ||
|
|
98c60789a2 | ||
|
|
1dcad051a8 | ||
|
|
dee5c83fc0 | ||
|
|
a8984bc68c | ||
|
|
d433fe8a08 | ||
|
|
f72ce7c136 | ||
|
|
d6c43a50bd | ||
|
|
5b6be0cebc | ||
|
|
637c8e0fdf | ||
|
|
6301728d35 | ||
|
|
b170fb5ce8 | ||
|
|
67e9ce4693 | ||
|
|
c1eaa78ab7 | ||
|
|
9cd5e7ed61 | ||
|
|
28b5ffb4d6 | ||
|
|
7322547172 | ||
|
|
58bbcd591e | ||
|
|
98a5b52d8b | ||
|
|
4eb3a2a885 | ||
|
|
755c180659 | ||
|
|
2e078e4488 | ||
|
|
c0a814fdb3 | ||
|
|
4c0426c469 | ||
|
|
ded93feb57 | ||
|
|
afbd5db404 | ||
|
|
8d9ab741c8 | ||
|
|
162d89a42f | ||
|
|
93e2c04ec2 | ||
|
|
03fe6ee4e4 | ||
|
|
3022b0f5b1 | ||
|
|
28c57246d1 | ||
|
|
31d31293d3 | ||
|
|
34708d6d18 | ||
|
|
1a27f57950 | ||
|
|
676118ab0f | ||
|
|
e3d877d542 | ||
|
|
fe5d56c9b1 | ||
|
|
c6e5521687 | ||
|
|
9e08b02df2 | ||
|
|
c4aa9feee2 | ||
|
|
185e37602b | ||
|
|
a7c6678c72 | ||
|
|
281072be44 | ||
|
|
ab0b3b9a07 | ||
|
|
db60e367b4 | ||
|
|
2ab32e6bc6 | ||
|
|
b62d646271 | ||
|
|
d58f0d243c | ||
|
|
610b0b4dd6 | ||
|
|
8077e4f4f1 | ||
|
|
8c7cb0eff8 | ||
|
|
ec06ba7ad0 | ||
|
|
4bf49809f2 | ||
|
|
7e3001191c | ||
|
|
39db95352c | ||
|
|
374c779f7f | ||
|
|
bd25ff5913 | ||
|
|
2446ff5251 | ||
|
|
e7ad2fe207 | ||
|
|
a11a10525b | ||
|
|
7dd1a8da08 | ||
|
|
568691ce6a | ||
|
|
4adfc45b5a | ||
|
|
98e45a5995 | ||
|
|
56b5b7ee82 | ||
|
|
0dc5dd5808 | ||
|
|
1242c5434d | ||
|
|
c40b06cac9 | ||
|
|
e4be666c2c | ||
|
|
3a718d8c62 | ||
|
|
27e217caee | ||
|
|
fbdad6eac3 | ||
|
|
fe6cc0c15d | ||
|
|
726073fef7 | ||
|
|
1e73c25fbf | ||
|
|
d742814686 | ||
|
|
d078dce2f8 | ||
|
|
521d26c57f | ||
|
|
6edf55c04b | ||
|
|
941cd86881 | ||
|
|
0eeb2775a5 | ||
|
|
58183d425b | ||
|
|
9ac68670d7 | ||
|
|
71fb33a5fe | ||
|
|
388e05b4af | ||
|
|
f819416bac | ||
|
|
a08ce7dddb | ||
|
|
1e8f01253e | ||
|
|
f108746c15 | ||
|
|
b7ed6752ac | ||
|
|
788d58e5a3 | ||
|
|
64f093f9c4 | ||
|
|
8c7a28f211 | ||
|
|
58bc1458d0 | ||
|
|
ae37d202a5 | ||
|
|
5842e35881 | ||
|
|
5e28ff83cb | ||
|
|
5dfd7dd1bf | ||
|
|
3174507d57 | ||
|
|
edab5afff9 | ||
|
|
1925d01d8f | ||
|
|
87e8cdd3eb | ||
|
|
706c6eae60 | ||
|
|
853be621ac | ||
|
|
6264c60e97 | ||
|
|
bbc48fdad6 | ||
|
|
63a8df1c1f | ||
|
|
5ad83a6a65 | ||
|
|
fb8d5166a8 | ||
|
|
acdcb906ae | ||
|
|
6c447b12e3 | ||
|
|
41f718f779 | ||
|
|
d38b34756b | ||
|
|
d3d19ce49b | ||
|
|
e37ef3af21 | ||
|
|
0a0630c049 | ||
|
|
dc671c8ac4 | ||
|
|
03d3a5cdde | ||
|
|
b15d825bb3 | ||
|
|
630432b4e2 | ||
|
|
e44ae96100 | ||
|
|
985d4d6a43 | ||
|
|
0d0c8f07f2 | ||
|
|
1439183ad3 | ||
|
|
adecead716 | ||
|
|
6065b11634 | ||
|
|
4714a961b8 | ||
|
|
261612596d | ||
|
|
5af2ef5fbc | ||
|
|
75837a8252 | ||
|
|
e5fcf0bee5 | ||
|
|
d984ac9d09 | ||
|
|
ca2a36b1d7 | ||
|
|
7346621d15 | ||
|
|
ea49f7ca74 | ||
|
|
ee025b0558 | ||
|
|
e0efcc6ab0 | ||
|
|
6d3d00b445 | ||
|
|
d930c812bb | ||
|
|
bd9f56af9a | ||
|
|
2d7c12b0e9 | ||
|
|
1816a93b1b | ||
|
|
6cebeae15e | ||
|
|
edf6f0ca70 | ||
|
|
3d96a33bd0 | ||
|
|
c850ae1027 | ||
|
|
174b7a7f9c | ||
|
|
1f8f3ab0f8 | ||
|
|
44e2ee7b20 | ||
|
|
807ea2d3c1 | ||
|
|
e3ed74a5e8 | ||
|
|
2d12db000f | ||
|
|
a3cbcca13d | ||
|
|
a0b7d95e36 | ||
|
|
6cceb936a7 | ||
|
|
f7eeccba4b | ||
|
|
671436cbb8 | ||
|
|
9dda9b742f | ||
|
|
96a4e7b86e | ||
|
|
038ee99604 | ||
|
|
a6dae75d3a | ||
|
|
918921e821 | ||
|
|
a1f94f670e | ||
|
|
1ac9a2eb5b | ||
|
|
01a1fd615b | ||
|
|
77c1f15c9f | ||
|
|
d5bb7585da | ||
|
|
a0a56e2cb3 | ||
|
|
4dbcaf76c3 | ||
|
|
02693bc02f | ||
|
|
9376ee42f4 | ||
|
|
7111b4cd5f | ||
|
|
08cffd6a30 | ||
|
|
29173bf814 | ||
|
|
c5859337b6 | ||
|
|
99ff715137 | ||
|
|
6df36232a0 | ||
|
|
9e5106d90e | ||
|
|
24e5868818 | ||
|
|
e990c35476 | ||
|
|
a5a6e22316 | ||
|
|
19d0405aa5 | ||
|
|
fdef940127 | ||
|
|
93b0a4e005 | ||
|
|
19fd1622f5 | ||
|
|
e3e466d3e5 | ||
|
|
a7ebb2145c | ||
|
|
935f819207 | ||
|
|
5fb6c0dd14 | ||
|
|
55ad6f0e23 | ||
|
|
77e28cf65b | ||
|
|
41673b7382 | ||
|
|
53d8e49dca | ||
|
|
f5f3f77286 | ||
|
|
097c7b9cdd | ||
|
|
ffabec3a5e | ||
|
|
2f5424bdac | ||
|
|
18ac72e457 | ||
|
|
eb98e33a85 | ||
|
|
e0ab836b2d | ||
|
|
ea0e06f980 | ||
|
|
68f7aebcaf | ||
|
|
a1f763ee75 | ||
|
|
fbcbb29884 | ||
|
|
eb0291d9a5 | ||
|
|
35781597d0 | ||
|
|
35c2225f50 | ||
|
|
4511624e79 | ||
|
|
c6aeebb18d | ||
|
|
7b2e12b102 | ||
|
|
c4f1c75efa | ||
|
|
0156f693e0 | ||
|
|
0139e102e3 | ||
|
|
e798fb720e | ||
|
|
0467a9075f | ||
|
|
dda5ee2e9f | ||
|
|
ae78a336e1 | ||
|
|
16f261e773 | ||
|
|
c2b3ed09a0 | ||
|
|
32d8c8ba94 | ||
|
|
84e5b075b4 | ||
|
|
e980948de5 | ||
|
|
d1c5b6fe9e | ||
|
|
65dc00f321 | ||
|
|
bf191df9c0 | ||
|
|
4567cd4ca2 | ||
|
|
657635c1c0 | ||
|
|
dec191aa1e | ||
|
|
1d57754d46 | ||
|
|
2901fd595b | ||
|
|
f0dad26a5b | ||
|
|
f7e420bf29 | ||
|
|
c6696d8399 | ||
|
|
cf224560bc | ||
|
|
cbd7f2b9aa | ||
|
|
df9b67894a | ||
|
|
43fc40e9b4 | ||
|
|
a2f0c11474 | ||
|
|
ff4d6dded5 | ||
|
|
3e9ce35023 | ||
|
|
99e2ca408b | ||
|
|
db0d7d4ea8 | ||
|
|
b317d86a93 | ||
|
|
bfe01b52ab | ||
|
|
02b3cca522 | ||
|
|
ef92339d07 | ||
|
|
af2fad9473 | ||
|
|
fdad140997 | ||
|
|
5141ea4f06 | ||
|
|
d21e6af1d2 | ||
|
|
678b7da5b3 | ||
|
|
086c3f0799 | ||
|
|
53d952a4ce | ||
|
|
7b85a7259f | ||
|
|
66a6a1fced | ||
|
|
7f0d93a2da | ||
|
|
b212b64214 | ||
|
|
256d1b0dfc | ||
|
|
76db642543 | ||
|
|
d52bcd46ec | ||
|
|
652c683da7 | ||
|
|
0b169792af | ||
|
|
91efe5a611 | ||
|
|
01bb2ac97b | ||
|
|
6567ba821a | ||
|
|
48d6850d9a | ||
|
|
e300518597 | ||
|
|
0b179c87f1 | ||
|
|
7d7d2a53b1 | ||
|
|
47bbdf415c | ||
|
|
a73a5cf914 | ||
|
|
add924cdb2 | ||
|
|
c89bdd7566 | ||
|
|
b90b0c3cfa | ||
|
|
7d9818e21a | ||
|
|
3fe7add2c5 | ||
|
|
b40027beb9 | ||
|
|
9f491ffeb9 | ||
|
|
840ad0a35a | ||
|
|
3589e0f442 | ||
|
|
ed593c91fb | ||
|
|
5f6ec2211d | ||
|
|
3ac6d550ca | ||
|
|
0ca200f322 | ||
|
|
b376f31af9 | ||
|
|
14c6802438 | ||
|
|
f8703e3e59 | ||
|
|
03256bd9f8 | ||
|
|
56d44fbf1c | ||
|
|
38bf24a6e5 | ||
|
|
c8d20a456b | ||
|
|
ab82cafcde | ||
|
|
a6079bc9ce | ||
|
|
68b40dd91d | ||
|
|
c7334363b3 | ||
|
|
73f4114f59 | ||
|
|
f831872125 | ||
|
|
ff2f7372f2 | ||
|
|
d219ecd05c | ||
|
|
2e2464bf07 | ||
|
|
668cd471a1 | ||
|
|
58763b0e91 | ||
|
|
74e97ef91b | ||
|
|
2eac84296b | ||
|
|
c56c4a8dc8 | ||
|
|
7ce741dacd | ||
|
|
31b4390042 | ||
|
|
2345c6db0c | ||
|
|
d455cb65a6 | ||
|
|
6d09160f5b | ||
|
|
4a06dd1295 | ||
|
|
eaf332f83f | ||
|
|
1ecda83da7 | ||
|
|
533c2471c2 | ||
|
|
135abccd9c | ||
|
|
1398431bca | ||
|
|
ca9e5a0ee1 | ||
|
|
3392eb7de2 | ||
|
|
0e40f9b868 | ||
|
|
9f74f95f69 | ||
|
|
452ac55a28 | ||
|
|
b456ff1090 | ||
|
|
043a25992a | ||
|
|
f7643f7bbe | ||
|
|
af00ec8970 | ||
|
|
f830eb7101 | ||
|
|
026afc2c1a | ||
|
|
63398d6ae4 | ||
|
|
d9fa180cf9 | ||
|
|
4866e2672f | ||
|
|
a5d41c9f6c | ||
|
|
cdcc50f365 | ||
|
|
5397021efb | ||
|
|
c9b53539d5 | ||
|
|
116ecf246e | ||
|
|
9572521e3c | ||
|
|
8a059cccb8 | ||
|
|
2c54f72670 | ||
|
|
705d7b36af | ||
|
|
1b827fe136 | ||
|
|
0d68ca8eb9 | ||
|
|
cb50241e6f | ||
|
|
f1c0c043b5 | ||
|
|
596832371c | ||
|
|
1be67b8851 | ||
|
|
3c175cb511 | ||
|
|
936516cb9c | ||
|
|
7b161f93a0 | ||
|
|
164ddf668f | ||
|
|
e9bf206d88 | ||
|
|
fe93a7e084 | ||
|
|
207735cedc | ||
|
|
900e57657e | ||
|
|
565d7b3747 | ||
|
|
32b0d71af7 | ||
|
|
7c49612d4b | ||
|
|
fa5a37e51a | ||
|
|
b380f16367 | ||
|
|
b710a43232 | ||
|
|
aff3625d4f | ||
|
|
eb43ce4d4f | ||
|
|
c9107e35fa | ||
|
|
0ba2bcb545 | ||
|
|
eec7cf7634 | ||
|
|
63ff6a07eb | ||
|
|
599f0f5cef | ||
|
|
2b52cdc915 | ||
|
|
67025e63e4 | ||
|
|
e848d25c86 | ||
|
|
0a2e0c0e3e | ||
|
|
8023250ee7 | ||
|
|
7cabc1c490 | ||
|
|
404ce57bcc | ||
|
|
b82ea98c71 | ||
|
|
a4d09ab0a8 | ||
|
|
3af8179878 | ||
|
|
6c6b1053b7 | ||
|
|
9d2d60691e | ||
|
|
06e9d86cb3 | ||
|
|
dedf43288e | ||
|
|
685b2604e4 | ||
|
|
624a4464ca | ||
|
|
8d14ee3540 | ||
|
|
09846c725b | ||
|
|
43bd568f1c | ||
|
|
ca5f371f1a | ||
|
|
62ba2499e0 | ||
|
|
077892645b | ||
|
|
aac6275300 | ||
|
|
e7c4f3672e | ||
|
|
1c8b1096c6 | ||
|
|
8411b9e142 | ||
|
|
4099c28776 | ||
|
|
941e36f48a | ||
|
|
f46940228e | ||
|
|
d744e51c1b | ||
|
|
ee5bc1a5c4 | ||
|
|
ae3c3d80ee | ||
|
|
56d8b445ed | ||
|
|
cee6cf70ce | ||
|
|
09d1f2f18f | ||
|
|
640a6633b1 | ||
|
|
a6bc39d3c6 | ||
|
|
aaed72b723 | ||
|
|
41bd6c2717 | ||
|
|
9ffcd83027 | ||
|
|
5401b92aac | ||
|
|
80e1afb654 | ||
|
|
001676c7a9 | ||
|
|
a33eed71af | ||
|
|
8bf76ffa52 | ||
|
|
f95f5dcd79 | ||
|
|
0d5de4333d | ||
|
|
5ac3b57f9b | ||
|
|
98b1c58218 | ||
|
|
eb28ee7905 | ||
|
|
c8ad52b89d | ||
|
|
273e9557be | ||
|
|
764966e398 | ||
|
|
c4c817116f | ||
|
|
e37160f4e3 | ||
|
|
57b3ba425e | ||
|
|
4e132f18c4 | ||
|
|
b0077dcd0c | ||
|
|
8c2e6b70b8 | ||
|
|
6a77453532 | ||
|
|
2aea7dd921 | ||
|
|
2a0dcc5cae | ||
|
|
2c2249ee73 | ||
|
|
b19b8b593a | ||
|
|
40d77bacc3 | ||
|
|
b8be7237b8 | ||
|
|
ffe31405ff | ||
|
|
be0f383568 | ||
|
|
b2a6720477 | ||
|
|
0a591a9697 | ||
|
|
5c4547e84d | ||
|
|
d6234b764e | ||
|
|
8883a0144b | ||
|
|
75e6dfbfd3 | ||
|
|
41078997ae | ||
|
|
9c7fe34c50 | ||
|
|
9042d19c4e | ||
|
|
12c909eecc | ||
|
|
bb78120283 | ||
|
|
5b51392724 | ||
|
|
b6b3c6f29b | ||
|
|
d70127cee6 | ||
|
|
77d42373a1 | ||
|
|
bb04e69a92 | ||
|
|
b509862bfa | ||
|
|
2685b960d7 | ||
|
|
60e5a0e46f | ||
|
|
7365f40300 | ||
|
|
09d07553ab | ||
|
|
e272fd6909 | ||
|
|
90d458820b | ||
|
|
9f3c3e0918 | ||
|
|
6b322f47a0 | ||
|
|
4fcb9ebf30 | ||
|
|
53529bd05d | ||
|
|
8d650a7250 | ||
|
|
12a096b5f1 | ||
|
|
6f3076325e | ||
|
|
8c8883ef26 | ||
|
|
4b555fdf4c | ||
|
|
863734aba4 | ||
|
|
1f4b9fe749 | ||
|
|
2a6c363a8a | ||
|
|
643f96c79b | ||
|
|
2b2994badc | ||
|
|
eaecd0e8b7 | ||
|
|
2e940e635d | ||
|
|
8b91ac5d7e | ||
|
|
7faa73a561 | ||
|
|
042e071a64 | ||
|
|
b8fd3f65d9 | ||
|
|
efd7849ed0 | ||
|
|
adf2e872f8 | ||
|
|
ed8b3cc9ea | ||
|
|
7ec0bd93b0 | ||
|
|
3d158f4448 | ||
|
|
250c3ae3c1 | ||
|
|
94c9cc2300 | ||
|
|
e9f36b5041 | ||
|
|
30808f9f0b | ||
|
|
af670fc718 | ||
|
|
4bbe716aa0 | ||
|
|
a7af4a8837 | ||
|
|
89feedad98 | ||
|
|
728b3f939c | ||
|
|
7db6978012 | ||
|
|
6261dd65d3 | ||
|
|
a45cc112e5 | ||
|
|
b8aa967226 | ||
|
|
6e4308bfde | ||
|
|
dd12912124 | ||
|
|
937153a92f | ||
|
|
c412cd7521 | ||
|
|
4a6fb9a7d4 | ||
|
|
824e92229d | ||
|
|
0b59141054 | ||
|
|
b9ad51049e | ||
|
|
d2341654fe | ||
|
|
169d4c3bff | ||
|
|
13d64e6fa6 | ||
|
|
f83b3d7fc1 | ||
|
|
f2bbad36d5 | ||
|
|
77c0788b2c | ||
|
|
4e79e39e22 | ||
|
|
32fe72f909 | ||
|
|
1e63f3756e | ||
|
|
8fa3a89482 | ||
|
|
9c76129a23 | ||
|
|
01ceda5b0c | ||
|
|
eeb4c14754 | ||
|
|
bcb7c721dc | ||
|
|
0da65becd3 | ||
|
|
422a4dda68 | ||
|
|
222137dcd1 | ||
|
|
372a405926 | ||
|
|
dfd63bdb6b | ||
|
|
5b39737d49 | ||
|
|
904aecfdb7 | ||
|
|
a28754b892 | ||
|
|
b43e742503 | ||
|
|
8ac25d37d9 | ||
|
|
77b6a7d5bd | ||
|
|
aa25608c52 | ||
|
|
b0ab37ddc0 | ||
|
|
3141f7cb04 | ||
|
|
7ba9440053 | ||
|
|
f97316319f | ||
|
|
405b487dc3 | ||
|
|
b48b782c87 | ||
|
|
74763ef3fb | ||
|
|
74ebb650df | ||
|
|
a363b90fa5 | ||
|
|
6aab9c3d64 | ||
|
|
2dc70af717 | ||
|
|
46acfac327 | ||
|
|
727b29c85d | ||
|
|
e0e271162c | ||
|
|
cfc68677ee | ||
|
|
43c4d80b12 | ||
|
|
05c9e30163 | ||
|
|
b6167d8c3b | ||
|
|
56e8ef2d38 | ||
|
|
db512d8f62 | ||
|
|
5249cf33e5 | ||
|
|
09bde74e43 | ||
|
|
a4dbfdce59 | ||
|
|
dea48d64a5 | ||
|
|
178439ef8c | ||
|
|
f1194afd7c | ||
|
|
2742923df4 | ||
|
|
0b38c5d8b3 | ||
|
|
f451be0519 | ||
|
|
f991bd46f3 | ||
|
|
139e56c774 | ||
|
|
e7eda72c9d | ||
|
|
980243f2d5 | ||
|
|
b6ddd4ce41 | ||
|
|
6caeaeb391 | ||
|
|
290938bf80 | ||
|
|
0225851e40 | ||
|
|
2a7f749d5a | ||
|
|
57ca3d7843 | ||
|
|
de8d26d791 | ||
|
|
5be6630843 | ||
|
|
446bbfe9eb | ||
|
|
f2f31a14c9 | ||
|
|
e92cbc444b | ||
|
|
baffbdb541 | ||
|
|
b7740d4859 | ||
|
|
599cde3627 | ||
|
|
bd2bb0e1c7 | ||
|
|
03580b23a3 | ||
|
|
9d747d14c5 | ||
|
|
124afeb843 | ||
|
|
05cbf70486 | ||
|
|
58d1589a55 | ||
|
|
49ad279c52 | ||
|
|
1fbaf8816e | ||
|
|
b4d651055a | ||
|
|
c5b6c4da43 | ||
|
|
f628981f42 | ||
|
|
a663ea4d2c | ||
|
|
2be68e4125 | ||
|
|
317f24076e | ||
|
|
fab3153de6 | ||
|
|
276dddcbfb | ||
|
|
2adb5815bf | ||
|
|
3df99930e8 | ||
|
|
e54c21bc65 | ||
|
|
bbfc715821 | ||
|
|
755f3798d1 | ||
|
|
5b716c5b0c | ||
|
|
b0e53e9c6d | ||
|
|
c55b5c8c19 | ||
|
|
fb1dd6b53a | ||
|
|
0e61fca974 | ||
|
|
2b6e6d8631 | ||
|
|
47151fc2a9 | ||
|
|
5027787aec | ||
|
|
c79ac4d9fc | ||
|
|
f9f3661090 | ||
|
|
ae716872b9 | ||
|
|
ea19faa411 | ||
|
|
9a1c56c5b9 | ||
|
|
214981f0b1 | ||
|
|
16847a3c13 | ||
|
|
54a7fdadda | ||
|
|
1c275afd7c | ||
|
|
8030612e52 | ||
|
|
257371da28 | ||
|
|
5955498aca | ||
|
|
fc4bddf82a | ||
|
|
bd349650a7 | ||
|
|
88a62d5fea | ||
|
|
b0b62d63cf | ||
|
|
15b53509da | ||
|
|
153a030c1f | ||
|
|
2583ad5da7 | ||
|
|
a6510d6a61 | ||
|
|
407bc77d34 | ||
|
|
766b91d306 | ||
|
|
b385aedf36 | ||
|
|
99612ba14d | ||
|
|
ec0227a476 | ||
|
|
2617d3c9f3 | ||
|
|
6367f603f6 | ||
|
|
d3c9384c9c | ||
|
|
026691702d | ||
|
|
605ee8587b | ||
|
|
819e04a7ab | ||
|
|
46b9e25190 | ||
|
|
1726651c71 | ||
|
|
e3303ac3a2 | ||
|
|
67a74c33e1 | ||
|
|
97cbbb176b | ||
|
|
5af1a552bc | ||
|
|
97d23de247 | ||
|
|
863a70918a | ||
|
|
6fbaf0a036 | ||
|
|
d827544fbd | ||
|
|
12187efdbd | ||
|
|
7c6000c5e3 | ||
|
|
a88b7239b5 | ||
|
|
0a3759f683 | ||
|
|
da5d92812e | ||
|
|
ff3454ef89 | ||
|
|
4625881c54 | ||
|
|
4c2308b4c6 | ||
|
|
7ce58dbd4a | ||
|
|
2388467bd3 | ||
|
|
d7096569c8 | ||
|
|
fcacf1bc0d | ||
|
|
2e5a6476d5 | ||
|
|
72a33cb8c2 | ||
|
|
72a7f2b3ed | ||
|
|
a8db9884d5 | ||
|
|
1330e2d246 | ||
|
|
9ba4eff279 | ||
|
|
e5fac8c32f | ||
|
|
a07c3c2f94 | ||
|
|
828640ca26 | ||
|
|
9e4c39ae53 | ||
|
|
0e44ecd420 | ||
|
|
849c6324d3 | ||
|
|
691e96c5cf | ||
|
|
6544d22338 | ||
|
|
5e491260a1 | ||
|
|
f16a0790ca | ||
|
|
b441469044 | ||
|
|
88133d0d77 | ||
|
|
fee9a218e8 | ||
|
|
51ff5ddb64 | ||
|
|
65e8c92d7c | ||
|
|
f2fdb93318 | ||
|
|
5da734c3d4 | ||
|
|
993411d9fe | ||
|
|
215740157b | ||
|
|
645e09e859 | ||
|
|
495cfa96c2 | ||
|
|
0f38d807c7 | ||
|
|
df324e2c21 | ||
|
|
cd52424fb7 | ||
|
|
5b9cdc5cd2 | ||
|
|
a6605155f0 | ||
|
|
a5267e1163 | ||
|
|
8b906c69bb | ||
|
|
8c0a940cdb | ||
|
|
a36a65b36a | ||
|
|
2be9ebaad2 | ||
|
|
7994b5612a | ||
|
|
7b38f46caf | ||
|
|
609a545131 | ||
|
|
a53404fac3 | ||
|
|
69d69f25b9 | ||
|
|
44ac5fe6df | ||
|
|
d43f78c845 | ||
|
|
e5264aba37 | ||
|
|
ca75eb509a | ||
|
|
5b8f02243c | ||
|
|
76634db9be |
26
.commitlintrc.json
Normal file
26
.commitlintrc.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"extends": ["@commitlint/config-angular"],
|
||||
"rules": {
|
||||
"scope-case": [2, "always", "pascal-case"],
|
||||
"type-enum": [
|
||||
2,
|
||||
"always",
|
||||
[
|
||||
"chore",
|
||||
"build",
|
||||
"ci",
|
||||
"docs",
|
||||
"feat",
|
||||
"fix",
|
||||
"perf",
|
||||
"refactor",
|
||||
"revert",
|
||||
"style",
|
||||
"test",
|
||||
"types",
|
||||
"workflow",
|
||||
"wip"
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,12 @@
|
||||
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
|
||||
"plugins": ["import"],
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 2019
|
||||
"ecmaVersion": 2021
|
||||
},
|
||||
"env": {
|
||||
"es6": true,
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"overrides": [{ "files": ["*.browser.js"], "env": { "browser": true } }],
|
||||
"rules": {
|
||||
"import/order": [
|
||||
"error",
|
||||
@@ -26,7 +25,8 @@
|
||||
"singleQuote": true,
|
||||
"quoteProps": "as-needed",
|
||||
"trailingComma": "all",
|
||||
"endOfLine": "lf"
|
||||
"endOfLine": "lf",
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
],
|
||||
"strict": ["error", "global"],
|
||||
|
||||
76
.github/CODE_OF_CONDUCT.md
vendored
Normal file
76
.github/CODE_OF_CONDUCT.md
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||
level of experience, education, socio-economic status, nationality, personal
|
||||
appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at https://discord.gg/djs. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see
|
||||
https://www.contributor-covenant.org/faq
|
||||
13
.github/CONTRIBUTING.md
vendored
13
.github/CONTRIBUTING.md
vendored
@@ -1,6 +1,6 @@
|
||||
# Contributing
|
||||
|
||||
**The issue tracker is only for bug reports and enhancement suggestions. If you have a question, please ask it in the [Discord server](https://discord.gg/bRCvFy9) instead of opening an issue – you will get redirected there anyway.**
|
||||
**The issue tracker is only for bug reports and enhancement suggestions. If you have a question, please ask it in the [Discord server](https://discord.gg/djs) instead of opening an issue – you will get redirected there anyway.**
|
||||
|
||||
If you wish to contribute to the discord.js codebase or documentation, feel free to fork the repository and submit a
|
||||
pull request. We use ESLint to enforce a consistent coding style, so having that set up in your editor of choice
|
||||
@@ -10,9 +10,8 @@ is a great boon to your development process.
|
||||
|
||||
To get ready to work on the codebase, please do the following:
|
||||
|
||||
1. Fork & clone the repository, and make sure you're on the **master** branch
|
||||
2. Run `npm install`
|
||||
3. If you're working on voice, also run `npm install @discordjs/opus` or `npm install opusscript`
|
||||
4. Code your heart out!
|
||||
5. Run `npm test` to run ESLint and ensure any JSDoc changes are valid
|
||||
6. [Submit a pull request](https://github.com/discordjs/discord.js/compare)
|
||||
1. Fork & clone the repository, and make sure you're on the **main** branch
|
||||
2. Run `npm ci`
|
||||
3. Code your heart out!
|
||||
4. Run `npm test` to run ESLint and ensure any JSDoc changes are valid
|
||||
5. [Submit a pull request](https://github.com/discordjs/discord.js/compare) (Make sure you follow the [conventional commit format](https://github.com/discordjs/discord.js-modules/blob/main/.github/COMMIT_CONVENTION.md))
|
||||
|
||||
11
.github/FUNDING.yml
vendored
11
.github/FUNDING.yml
vendored
@@ -1,11 +1,2 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
# github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
# patreon: # Replace with a single Patreon username
|
||||
# open_collective: # Replace with a single Open Collective username
|
||||
# ko_fi: # Replace with a single Ko-fi username
|
||||
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
# custom: # Replace with a single custom sponsorship URL
|
||||
|
||||
github: amishshah
|
||||
github: [amishshah, iCrawl, vladfrangu, kyranet]
|
||||
patreon: discordjs
|
||||
|
||||
31
.github/ISSUE_TEMPLATE/bug_report.md
vendored
31
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,17 +1,13 @@
|
||||
---
|
||||
|
||||
name: Bug report
|
||||
about: Report incorrect or unexpected behaviour of discord.js
|
||||
about: Report incorrect or unexpected behavior of discord.js
|
||||
title: ''
|
||||
labels: 's: unverified, type: bug'
|
||||
labels: 'bug, need repro'
|
||||
assignees: ''
|
||||
---
|
||||
<!--
|
||||
If you need help with discord.js installation or usage, please go to the discord.js Discord server instead:
|
||||
https://discord.gg/bRCvFy9
|
||||
This issue tracker is only for bug reports and enhancement suggestions.
|
||||
You won't receive any basic help here.
|
||||
-->
|
||||
<!-- Use Discord for questions: https://discord.gg/djs -->
|
||||
<!-- If you are reporting a voice issue, please post your issue at https://github.com/discordjs/voice/issues -->
|
||||
|
||||
**Please describe the problem you are having in as much detail as possible:**
|
||||
|
||||
@@ -28,12 +24,15 @@ You won't receive any basic help here.
|
||||
- Operating system:
|
||||
- Priority this issue should have – please be realistic and elaborate if possible:
|
||||
|
||||
<!--
|
||||
If this applies to you, please check the respective checkbox: [ ] becomes [x].
|
||||
You don't have to modify the text to suit your particular situation – if you want to
|
||||
elaborate, please do so in the description.
|
||||
While it's not a requirement to test your issue on the master branch, it would make fixing
|
||||
the problem a lot easier for us, so please do so if possible.
|
||||
-->
|
||||
**Relevant client options:**
|
||||
|
||||
- [ ] I have also tested the issue on latest master, commit hash:
|
||||
- partials: none
|
||||
- gateway intents: none
|
||||
- other: none
|
||||
|
||||
<!--
|
||||
Remove the comment and fill out the commit hash if this applies to you:
|
||||
(While it's not a requirement to test your issue on the main branch, it would make fixing the problem a lot easier for us, so please do so if possible.)
|
||||
|
||||
- I have also tested the issue on latest main; Commit hash: `xxx`
|
||||
-->
|
||||
|
||||
6
.github/ISSUE_TEMPLATE/config.yml
vendored
6
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,5 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: discord.js discord server
|
||||
url: https://discord.gg/bRCvFy9
|
||||
about: Please use this Discord Server to ask questions and get support. We don't typically answer questions here and they will likely be closed and redirected to the Discord server.
|
||||
- name: Discord server
|
||||
url: https://discord.gg/djs
|
||||
about: Please visit our Discord server for questions and support requests.
|
||||
|
||||
11
.github/ISSUE_TEMPLATE/feature_request.md
vendored
11
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -3,18 +3,13 @@
|
||||
name: Feature request
|
||||
about: Request a feature for the core discord.js library
|
||||
title: ''
|
||||
labels: 'type: enhancement'
|
||||
labels: 'feature request'
|
||||
assignees: ''
|
||||
---
|
||||
<!--
|
||||
If you need help with discord.js installation or usage, please go to the discord.js Discord server instead:
|
||||
https://discord.gg/bRCvFy9
|
||||
This issue tracker is only for bug reports and enhancement suggestions.
|
||||
You likely won't receive any basic help here.
|
||||
-->
|
||||
<!-- Use Discord for questions: https://discord.gg/djs -->
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
A clear and concise description of what the problem is. Eg. I'm always frustrated when [...]
|
||||
|
||||
**Describe the ideal solution**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -1,12 +1,14 @@
|
||||
**Please describe the changes this PR makes and why it should be merged:**
|
||||
|
||||
**Status**
|
||||
|
||||
- [ ] Code changes have been tested against the Discord API, or there are no code changes
|
||||
- [ ] I know how to update typings and have done so, or typings don't need updating
|
||||
|
||||
**Semantic versioning classification:**
|
||||
**Status and versioning classification:**
|
||||
|
||||
- [ ] This PR changes the library's interface (methods or parameters added)
|
||||
- [ ] This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
|
||||
- [ ] This PR **only** includes non-code changes, like changes to documentation, README, etc.
|
||||
<!--
|
||||
Please move lines that apply to you out of the comment:
|
||||
- Code changes have been tested against the Discord API, or there are no code changes
|
||||
- I know how to update typings and have done so, or typings don't need updating
|
||||
- This PR changes the library's interface (methods or parameters added)
|
||||
- This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
|
||||
- This PR **only** includes non-code changes, like changes to documentation, README, etc.
|
||||
-->
|
||||
|
||||
6
.github/SUPPORT.md
vendored
6
.github/SUPPORT.md
vendored
@@ -1,7 +1,7 @@
|
||||
# Seeking support?
|
||||
|
||||
We're sorry, we only use this issue tracker for bugs in the library itself and feature requests for it. We are not able to provide general support or answser questions on the issue tracker.
|
||||
We only use this issue tracker for bug reports and feature request. We are not able to provide general support or answer questions in the form of GitHub issues.
|
||||
|
||||
Should you want to ask such questions, please post in one of our support channels in our Discord server: https://discord.gg/bRCvFy9
|
||||
For general questions about discord.js installation and use please use the dedicated support channels in our Discord server: https://discord.gg/djs
|
||||
|
||||
Any issues that don't directly involve a bug in the library or a feature request will likely be closed and redirected to the Discord server.
|
||||
Any issues that don't directly involve a bug or a feature request will likely be closed and redirected.
|
||||
|
||||
80
.github/labels.yml
vendored
Normal file
80
.github/labels.yml
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
- name: 'api changes'
|
||||
color: '5663e9'
|
||||
- name: 'api support'
|
||||
color: '5663e9'
|
||||
- name: 'backlog'
|
||||
color: '7ef7ef'
|
||||
- name: 'bug'
|
||||
color: 'd73a4a'
|
||||
- name: 'caching'
|
||||
color: '80c042'
|
||||
- name: 'chore'
|
||||
color: 'ffffff'
|
||||
- name: 'ci'
|
||||
color: '0075ca'
|
||||
- name: 'dependencies'
|
||||
color: '276bd1'
|
||||
- name: 'discussion'
|
||||
color: 'b6b1f9'
|
||||
- name: 'discord'
|
||||
color: '5663e9'
|
||||
- name: 'documentation'
|
||||
color: '0075ca'
|
||||
- name: 'duplicate'
|
||||
color: 'cfd3d7'
|
||||
- name: 'error handling'
|
||||
color: '80c042'
|
||||
- name: 'feature request'
|
||||
color: 'fcf95a'
|
||||
- name: 'gateway'
|
||||
color: '80c042'
|
||||
- name: 'good first issue'
|
||||
color: '7057ff'
|
||||
- name: 'has PR'
|
||||
color: '4b1f8e'
|
||||
- name: 'help wanted'
|
||||
color: '008672'
|
||||
- name: 'interactions'
|
||||
color: '80c042'
|
||||
- name: 'in progress'
|
||||
color: 'ffccd7'
|
||||
- name: 'in review'
|
||||
color: 'aed5fc'
|
||||
- name: 'invalid'
|
||||
color: 'e4e669'
|
||||
- name: 'need repro'
|
||||
color: 'c66037'
|
||||
- name: 'performance'
|
||||
color: '80c042'
|
||||
- name: 'permissions'
|
||||
color: '80c042'
|
||||
- name: 'priority:high'
|
||||
color: 'fc1423'
|
||||
- name: 'question (please use Discord instead)'
|
||||
color: 'd876e3'
|
||||
- name: 'ratelimits'
|
||||
color: '80c042'
|
||||
- name: 'refactor'
|
||||
color: '1d637f'
|
||||
- name: 'regression'
|
||||
color: 'ea8785'
|
||||
- name: 'REST'
|
||||
color: '80c042'
|
||||
- name: 'semver:major'
|
||||
color: 'c10f47'
|
||||
- name: 'semver:minor'
|
||||
color: 'e4f486'
|
||||
- name: 'semver:patch'
|
||||
color: 'e8be8b'
|
||||
- name: 'sharding'
|
||||
color: '80c042'
|
||||
- name: 'tests'
|
||||
color: 'f06dff'
|
||||
- name: 'threads'
|
||||
color: '80c042'
|
||||
- name: 'typings'
|
||||
color: '80c042'
|
||||
- name: 'utility'
|
||||
color: '80c042'
|
||||
- name: 'wontfix'
|
||||
color: 'ffffff'
|
||||
18
.github/tsc.json
vendored
Normal file
18
.github/tsc.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"problemMatcher": [
|
||||
{
|
||||
"owner": "tsc",
|
||||
"pattern": [
|
||||
{
|
||||
"regexp": "^(?:\\s+\\d+\\>)?([^\\s].*)\\((\\d+),(\\d+)\\)\\s*:\\s+(error|warning|info)\\s+(\\w{1,2}\\d+)\\s*:\\s*(.*)$",
|
||||
"file": 1,
|
||||
"line": 2,
|
||||
"column": 3,
|
||||
"severity": 4,
|
||||
"code": 5,
|
||||
"message": 6
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
31
.github/workflows/deploy.yml
vendored
31
.github/workflows/deploy.yml
vendored
@@ -3,7 +3,6 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
- '!webpack'
|
||||
- '!docs'
|
||||
tags:
|
||||
- '*'
|
||||
@@ -13,37 +12,17 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@master
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@master
|
||||
- name: Install Node v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 16
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
run: npm ci
|
||||
|
||||
- name: Build and deploy documentation
|
||||
uses: discordjs/action-docs@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
webpack:
|
||||
name: webpack
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@master
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@master
|
||||
with:
|
||||
node-version: 12
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
|
||||
- name: Build and deploy webpack
|
||||
uses: discordjs/action-webpack@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
22
.github/workflows/labelsync.yml
vendored
Normal file
22
.github/workflows/labelsync.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
name: Label Sync
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- '.github/labels.yml'
|
||||
jobs:
|
||||
labeler:
|
||||
name: Labeler
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Run Label Sync
|
||||
uses: crazy-max/ghaction-github-labeler@v3
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
33
.github/workflows/publish-dev.yml
vendored
Normal file
33
.github/workflows/publish-dev.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
name: Publish dev
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 */12 * * *'
|
||||
jobs:
|
||||
npm:
|
||||
name: npm
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16
|
||||
registry-url: https://registry.npmjs.org/
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci --ignore-scripts
|
||||
|
||||
- name: Deprecate old versions
|
||||
run: npm deprecate discord.js@"~$(jq --raw-output '.version' package.json)" "no longer supported" || true
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
|
||||
- name: Publish
|
||||
run: |
|
||||
npm version --git-tag-version=false $(jq --raw-output '.version' package.json).$(date +%s).$(git rev-parse --short HEAD)
|
||||
npm publish --tag dev || true
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
53
.github/workflows/test-cron.yml
vendored
53
.github/workflows/test-cron.yml
vendored
@@ -8,51 +8,72 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
- name: Install Node v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 16
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
run: npm ci
|
||||
|
||||
- name: Run ESLint
|
||||
uses: icrawl/action-eslint@v1
|
||||
run: npm run lint
|
||||
|
||||
typings:
|
||||
name: TSLint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
- name: Install Node v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 16
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
run: npm ci
|
||||
|
||||
- name: Run TSLint
|
||||
run: npm run lint:typings
|
||||
|
||||
typescript:
|
||||
name: TypeScript
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Register Problem Matcher
|
||||
run: echo "##[add-matcher].github/tsc.json"
|
||||
|
||||
- name: Run TypeScript compiler
|
||||
run: npm run test:typescript
|
||||
|
||||
docs:
|
||||
name: Documentation
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
- name: Install Node v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 16
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
run: npm ci
|
||||
|
||||
- name: Test documentation
|
||||
run: npm run docs:test
|
||||
|
||||
47
.github/workflows/test.yml
vendored
47
.github/workflows/test.yml
vendored
@@ -8,16 +8,16 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
- name: Install Node v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 16
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
run: npm ci
|
||||
|
||||
- name: Run ESLint
|
||||
uses: icrawl/action-eslint@v1
|
||||
run: npm run lint
|
||||
|
||||
typings:
|
||||
name: TSLint
|
||||
@@ -26,17 +26,38 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
- name: Install Node v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 16
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
run: npm ci
|
||||
|
||||
- name: Run TSLint
|
||||
run: npm run lint:typings
|
||||
|
||||
typescript:
|
||||
name: TypeScript
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Register Problem Matcher
|
||||
run: echo "##[add-matcher].github/tsc.json"
|
||||
|
||||
- name: Run TypeScript compiler
|
||||
run: npm run test:typescript
|
||||
|
||||
docs:
|
||||
name: Documentation
|
||||
runs-on: ubuntu-latest
|
||||
@@ -44,13 +65,13 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
- name: Install Node v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 16
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
run: npm ci
|
||||
|
||||
- name: Test documentation
|
||||
run: npm run docs:test
|
||||
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -1,7 +1,6 @@
|
||||
# Packages
|
||||
node_modules/
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
|
||||
# Log files
|
||||
logs/
|
||||
@@ -18,5 +17,9 @@ deploy/deploy_key.pub
|
||||
# Miscellaneous
|
||||
.tmp/
|
||||
.vscode/
|
||||
.idea/
|
||||
docs/docs.json
|
||||
webpack/
|
||||
typings/index.js
|
||||
|
||||
# Autogenerated
|
||||
src/index.mjs
|
||||
|
||||
1
.husky/.gitignore
vendored
Normal file
1
.husky/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
_
|
||||
4
.husky/commit-msg
Executable file
4
.husky/commit-msg
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npx --no-install commitlint --edit $1
|
||||
4
.husky/pre-commit
Executable file
4
.husky/pre-commit
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npx --no-install lint-staged
|
||||
4
.lintstagedrc.json
Normal file
4
.lintstagedrc.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"*.{mjs,js}": "eslint --fix --ext mjs,js,ts",
|
||||
"*.{ts,json,yml,yaml}": "prettier --write"
|
||||
}
|
||||
26
.npmignore
26
.npmignore
@@ -1,26 +0,0 @@
|
||||
# Packages
|
||||
node_modules/
|
||||
yarn.lock
|
||||
|
||||
# Log files
|
||||
logs/
|
||||
*.log
|
||||
|
||||
# Authentication
|
||||
deploy/
|
||||
|
||||
# Miscellaneous
|
||||
.tmp/
|
||||
.vscode/
|
||||
docs/
|
||||
|
||||
# NPM ignore
|
||||
.eslintrc.json
|
||||
.gitattributes
|
||||
.gitignore
|
||||
.travis.yml
|
||||
webpack.config.js
|
||||
.github/
|
||||
test/
|
||||
tsconfig.json
|
||||
tslint.json
|
||||
7
.prettierrc.json
Normal file
7
.prettierrc.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"printWidth": 120,
|
||||
"trailingComma": "all",
|
||||
"endOfLine": "lf",
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
@@ -10,8 +10,5 @@
|
||||
"fullDocs": true,
|
||||
"strong": true
|
||||
},
|
||||
"webpack": {
|
||||
"configPath": "./webpack.config.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
350
CHANGELOG.md
Normal file
350
CHANGELOG.md
Normal file
@@ -0,0 +1,350 @@
|
||||
# [13.1.0](https://github.com/discordjs/discord.js/compare/13.0.1...13.1.0) (2021-08-12)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **Constants:** fix CDN endpoint typings ([#6332](https://github.com/discordjs/discord.js/issues/6332)) ([47d2ef3](https://github.com/discordjs/discord.js/commit/47d2ef3e40165d846b5a901709b26dfffea46ef2))
|
||||
* **ContextMenuInteractin:** store message as raw value ([#6400](https://github.com/discordjs/discord.js/issues/6400)) ([d9456a1](https://github.com/discordjs/discord.js/commit/d9456a1a76e66bc2bfffa4a4b1dd228132056e9f))
|
||||
* **Guild:** `preferredLocale` to always be a string ([#6402](https://github.com/discordjs/discord.js/issues/6402)) ([4a64662](https://github.com/discordjs/discord.js/commit/4a64662a7d5526817ad52fa3d2206dc11f38cb29))
|
||||
* **GuildMemberRoleManager:** typo ([#6335](https://github.com/discordjs/discord.js/issues/6335)) ([d87299b](https://github.com/discordjs/discord.js/commit/d87299ba2036ee19da22b5c8abfae3f9d355ea1e))
|
||||
* **Managers:** fix typo in unsupported warning ([#6338](https://github.com/discordjs/discord.js/issues/6338)) ([917e71a](https://github.com/discordjs/discord.js/commit/917e71a9ee7d8bd76d8dbea40b40a4fb28276f60))
|
||||
* **StageInstance:** Ensure `discoverableDisabled` is not `undefined` ([#6395](https://github.com/discordjs/discord.js/issues/6395)) ([dce8fc7](https://github.com/discordjs/discord.js/commit/dce8fc7b9d4603de26b1118058322aaa96ea699a))
|
||||
* **Util:** remove truthy check before isNaN check ([#6358](https://github.com/discordjs/discord.js/issues/6358)) ([3c17939](https://github.com/discordjs/discord.js/commit/3c17939fd53a1f139d95bd36dfdab85b46538a73))
|
||||
* **WidgetMember:** Default to `null` and not `undefined` ([#6399](https://github.com/discordjs/discord.js/issues/6399)) ([44bbfa5](https://github.com/discordjs/discord.js/commit/44bbfa5c46a4bb35777aec8681f18590dec9aea4))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **CommandInteractionResolvedData:** access to "raw" resolved data ([#6384](https://github.com/discordjs/discord.js/issues/6384)) ([fff887b](https://github.com/discordjs/discord.js/commit/fff887b2f43d19164dbf2878b00abead90a0703f))
|
||||
* **GuildManager:** allow setting with_counts to false ([#6407](https://github.com/discordjs/discord.js/issues/6407)) ([14aea12](https://github.com/discordjs/discord.js/commit/14aea1290061c225feb9d9f5378508d937e34a69))
|
||||
* **GuildMemberManager:** add 'list' method ([#6403](https://github.com/discordjs/discord.js/issues/6403)) ([2bf0970](https://github.com/discordjs/discord.js/commit/2bf09703c13afe7481071ae1b064dbc3513468e1))
|
||||
* **Utils:** add additional formatters ([#6388](https://github.com/discordjs/discord.js/issues/6388)) ([cd40292](https://github.com/discordjs/discord.js/commit/cd4029218fc8b67c395b3cd49a121b1bfa38f021))
|
||||
* **ContextMenus:** right-clickybois (context menu support for ApplicationCommand and CommandInteraction) ([#6176](https://github.com/discordjs/discord.js/issues/6176)) ([0266f28](https://github.com/discordjs/discord.js/commit/0266f280960729b27bf65ba0ee7b7bd8659f304d))
|
||||
* **Threads:** max autoArchiveDuration option ([#6304](https://github.com/discordjs/discord.js/issues/6304)) ([394d486](https://github.com/discordjs/discord.js/commit/394d48649fe4faef8c6b30d5c04962588f86261e))
|
||||
|
||||
|
||||
|
||||
## [13.0.1](https://github.com/discordjs/discord.js/compare/13.0.0...13.0.1) (2021-08-07)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **GuildMemberManager:** refactor fetchMany ([#6328](https://github.com/discordjs/discord.js/issues/6328)) ([909c873](https://github.com/discordjs/discord.js/commit/909c87353e24eb7947d1cabc78d9c0ee97c3902d))
|
||||
* **Message:** handle fetched messages ([#6325](https://github.com/discordjs/discord.js/issues/6325)) ([ceae596](https://github.com/discordjs/discord.js/commit/ceae5960edefc63be5f16a52e286e390c14e0d29))
|
||||
|
||||
|
||||
|
||||
# [13.0.0](https://github.com/discordjs/discord.js/compare/12.5.0...13.0.0) (2021-08-06)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **Action:** getChannel interaction DM ([#6280](https://github.com/discordjs/discord.js/issues/6280)) ([a72b5a3](https://github.com/discordjs/discord.js/commit/a72b5a355e443f17edf1b348f63d314c743093b9))
|
||||
* **BaseGuildTextChannel:** call patch ([#6298](https://github.com/discordjs/discord.js/issues/6298)) ([3eb4140](https://github.com/discordjs/discord.js/commit/3eb41405f412ee2b2d05c4245c4ebb80adfcec6b))
|
||||
* **Caching:** sweep archived threads in all channel caches ([#6312](https://github.com/discordjs/discord.js/issues/6312)) ([3725dca](https://github.com/discordjs/discord.js/commit/3725dcafc0cbb4a40d3ff66d2a9718e986f47c5b))
|
||||
* **Channel:** add default for destructured options ([#6203](https://github.com/discordjs/discord.js/issues/6203)) ([6872547](https://github.com/discordjs/discord.js/commit/68725476b39d5ef5793ccf62cfb468073e7d9cb2))
|
||||
* **ChannelUpdate:** restore accidentally removed line ([#6263](https://github.com/discordjs/discord.js/issues/6263)) ([774f5b7](https://github.com/discordjs/discord.js/commit/774f5b77ec6218c30360c773b5fe6185d1efd146))
|
||||
* **CommandInteractionOptionResolver:** Export CommandInteractionOptio… ([#6146](https://github.com/discordjs/discord.js/issues/6146)) ([8ccfd6e](https://github.com/discordjs/discord.js/commit/8ccfd6e07b3208568c495110c80990366637818e))
|
||||
* **CommandInteractionOptionResolver:** type should be USER ([#6148](https://github.com/discordjs/discord.js/issues/6148)) ([02f55f0](https://github.com/discordjs/discord.js/commit/02f55f09712af5d6a6f67b5ac369b1969801e23f))
|
||||
* **Guild:** add invite manager property, extend CachedManager ([#6049](https://github.com/discordjs/discord.js/issues/6049)) ([e3d877d](https://github.com/discordjs/discord.js/commit/e3d877d542518d0f82c476d921968338a859722b))
|
||||
* **GuildChannel:** Add missing 'cache' property ([#6019](https://github.com/discordjs/discord.js/issues/6019)) ([7e30011](https://github.com/discordjs/discord.js/commit/7e3001191c1529b9db09b6168ddd0c09931598f5))
|
||||
* **GuildChannel:** setParent not working ([#6276](https://github.com/discordjs/discord.js/issues/6276)) ([7e0618f](https://github.com/discordjs/discord.js/commit/7e0618f17a786708093bc532501b261191e85561))
|
||||
* **GuildChannel:** use map method on cache not its manager ([#6032](https://github.com/discordjs/discord.js/issues/6032)) ([d58f0d2](https://github.com/discordjs/discord.js/commit/d58f0d243c9bbd803cff7b8da2056c11e0416bef))
|
||||
* **GuildMemberManager:** fetchMany fixes ([#6314](https://github.com/discordjs/discord.js/issues/6314)) ([52817fc](https://github.com/discordjs/discord.js/commit/52817fc414eef5220043e055a740e4ad0f8287a0))
|
||||
* **Message:** fix thread getter ([#6309](https://github.com/discordjs/discord.js/issues/6309)) ([913c9fa](https://github.com/discordjs/discord.js/commit/913c9fa17672fa914776beb556edcee5cd2d2dc8))
|
||||
* **MessageMentions:** check guild exists before adding roles ([#6313](https://github.com/discordjs/discord.js/issues/6313)) ([1200bba](https://github.com/discordjs/discord.js/commit/1200bba7bcc48dab6a454925e533528a7e3c0cf7))
|
||||
* export various classes that are exported in the typings ([#6166](https://github.com/discordjs/discord.js/issues/6166)) ([30a58dc](https://github.com/discordjs/discord.js/commit/30a58dc80130d334bf8c85e7b37513c109beda1b))
|
||||
* remove support for overriding caches that break functionality ([#6282](https://github.com/discordjs/discord.js/issues/6282)) ([a6d4035](https://github.com/discordjs/discord.js/commit/a6d4035176ca784e75bd1cbdf30e039658c62fd4))
|
||||
* **CommandInteraction:** change options type from Collection to array ([#6139](https://github.com/discordjs/discord.js/issues/6139)) ([77784ac](https://github.com/discordjs/discord.js/commit/77784aca431709ff3c17095bd06f9e4016fbd11d))
|
||||
* **GuildAuditLog:** Assert `target` to null upon not finding invite codes ([#6171](https://github.com/discordjs/discord.js/issues/6171)) ([c8ca7bf](https://github.com/discordjs/discord.js/commit/c8ca7bfd2c5e7b29e54987a78301e9bdfa4a717b))
|
||||
* **GuildChannel:** clone its PermissionOverwriteManager too ([#6083](https://github.com/discordjs/discord.js/issues/6083)) ([f72ce7c](https://github.com/discordjs/discord.js/commit/f72ce7c136cf2dfe31a67b190c00e30ba7d70bfa))
|
||||
* **GuildChannel:** only fetch invites for the specific channel ([#6132](https://github.com/discordjs/discord.js/issues/6132)) ([c40c0f9](https://github.com/discordjs/discord.js/commit/c40c0f934a571c100e4b3aa633a80fe48661d836))
|
||||
* **InviteScope:** added missing 'bot' scope ([#6052](https://github.com/discordjs/discord.js/issues/6052)) ([93e2c04](https://github.com/discordjs/discord.js/commit/93e2c04ec27c44a8c955e576944023dc25075647))
|
||||
* **Message:** fix typo in sticker_items ([#6173](https://github.com/discordjs/discord.js/issues/6173)) ([870a0de](https://github.com/discordjs/discord.js/commit/870a0de53c01331c9357df4808fc0979ff17b9a4))
|
||||
* **Message:** make #channel and #guild getters ([#6271](https://github.com/discordjs/discord.js/issues/6271)) ([6e3236a](https://github.com/discordjs/discord.js/commit/6e3236ab64549d27445c631cbb3d88c2bb9bf289))
|
||||
* **PermissionOverwriteManager:** pass ID to API correctly ([#6026](https://github.com/discordjs/discord.js/issues/6026)) ([8077e4f](https://github.com/discordjs/discord.js/commit/8077e4f4f132f95c4fa21e9fc7313b93a2c4b9d7))
|
||||
* **PermissionOverwrites:** throw better error if resolving option fails ([#6219](https://github.com/discordjs/discord.js/issues/6219)) ([42a0313](https://github.com/discordjs/discord.js/commit/42a03130345d3a3841f5271d82a2cb8725b6fa0e))
|
||||
* **PermissionsOverwrites:** only convert type if number ([#6092](https://github.com/discordjs/discord.js/issues/6092)) ([dee5c83](https://github.com/discordjs/discord.js/commit/dee5c83fc0d1147d5b65151a8f91a4a089687a73))
|
||||
* **PresenceUpdate:** use added presence over nullable getter ([#6077](https://github.com/discordjs/discord.js/issues/6077)) ([637c8e0](https://github.com/discordjs/discord.js/commit/637c8e0fdfb4ce15361646017718c72c3d6af538))
|
||||
* **SelectMenuInteraction:** set values to empty array if not provided ([#6045](https://github.com/discordjs/discord.js/issues/6045)) ([34708d6](https://github.com/discordjs/discord.js/commit/34708d6d18f94b5c8d9c582973d057e1f89bfe1f))
|
||||
* **Sticker:** replace 'this.guildID' (undefined) by 'this.guildId' in fetchUser ([#6160](https://github.com/discordjs/discord.js/issues/6160)) ([07017a9](https://github.com/discordjs/discord.js/commit/07017a9699eecc4af7824ace39dd91e8b689f3c6))
|
||||
* **Structures:** remove Structures ([#6027](https://github.com/discordjs/discord.js/issues/6027)) ([ab0b3b9](https://github.com/discordjs/discord.js/commit/ab0b3b9a07f5e4987e4f25e41b2a007f2db06322))
|
||||
* **TeamMember:** Fixed incorrect return types. ([#6044](https://github.com/discordjs/discord.js/issues/6044)) ([fe5d56c](https://github.com/discordjs/discord.js/commit/fe5d56c9b11b3e5f05933c6d746237b9f353b392))
|
||||
* **TextBasedChannel:** Fix MessageCreate handling ([#6217](https://github.com/discordjs/discord.js/issues/6217)) ([6b85f90](https://github.com/discordjs/discord.js/commit/6b85f900fa8e6cc01f7ee14ae730950cf1635dd5))
|
||||
* **ThreadChannel:** better property handling ([#6172](https://github.com/discordjs/discord.js/issues/6172)) ([9679b90](https://github.com/discordjs/discord.js/commit/9679b9087200e29d2f488d84d115465449021b51))
|
||||
* **Util:** fix collection import ([#6256](https://github.com/discordjs/discord.js/issues/6256)) ([93e0239](https://github.com/discordjs/discord.js/commit/93e0239c8054293eac63338819a10490dbd49ff1))
|
||||
* **WebSocketShard:** mark shard ready if no guilds intent ([#6284](https://github.com/discordjs/discord.js/issues/6284)) ([09471be](https://github.com/discordjs/discord.js/commit/09471be30eea2540999c3d5a2b001a985a0d27cc))
|
||||
* array/keyArray removed ([#6245](https://github.com/discordjs/discord.js/issues/6245)) ([bf221f2](https://github.com/discordjs/discord.js/commit/bf221f2bef2871f019aa4a6978deb8460fff85b9))
|
||||
* Use `string` instead of `Snowflake` for invites ([#6202](https://github.com/discordjs/discord.js/issues/6202)) ([f060a3f](https://github.com/discordjs/discord.js/commit/f060a3fcd7e1ad30789d582e8baf28dbdddf8063))
|
||||
* **Typings:** type attachments to InteractionUpdateOptions ([#6162](https://github.com/discordjs/discord.js/issues/6162)) ([4f8ca29](https://github.com/discordjs/discord.js/commit/4f8ca2936a85109757fb3225e9d6cf9aae9714e2))
|
||||
* channel type check in actions ([#6086](https://github.com/discordjs/discord.js/issues/6086)) ([d433fe8](https://github.com/discordjs/discord.js/commit/d433fe8a0827e6275e2a7ceed537be38411f4f67))
|
||||
* Remove `connection.url` from open debug message ([#6018](https://github.com/discordjs/discord.js/issues/6018)) ([39db953](https://github.com/discordjs/discord.js/commit/39db95352c91faf175c2fd8ed365f293f965a0e4))
|
||||
* **Util:** splitMessage not working with array ([#6008](https://github.com/discordjs/discord.js/issues/6008)) ([bd25ff5](https://github.com/discordjs/discord.js/commit/bd25ff59133ba31713647d3e6a5ef66abc4d54fb))
|
||||
* correct permissions checks and cache on update ([#6015](https://github.com/discordjs/discord.js/issues/6015)) ([568691c](https://github.com/discordjs/discord.js/commit/568691ce6a7994adc85db2b2a5b2227ece8c8358))
|
||||
* typedefs and typings for image & webhook options ([#5805](https://github.com/discordjs/discord.js/issues/5805)) ([a5a6e22](https://github.com/discordjs/discord.js/commit/a5a6e223166cf9af430da9003780e6582ea17b1c))
|
||||
* **ApplicationCommand:** default option.required fix ([#5848](https://github.com/discordjs/discord.js/issues/5848)) ([a1f94f6](https://github.com/discordjs/discord.js/commit/a1f94f670e5b6009b9c33932ce06ed512447b953))
|
||||
* **ApplicationCommand:** default option.required to false ([#5838](https://github.com/discordjs/discord.js/issues/5838)) ([77c1f15](https://github.com/discordjs/discord.js/commit/77c1f15c9f7562465c07727602c3213ddcf02778))
|
||||
* **ApplicationCommand:** fix typo in JSDoc ([#5994](https://github.com/discordjs/discord.js/issues/5994)) ([6edf55c](https://github.com/discordjs/discord.js/commit/6edf55c04b970235fdc92c00808ee86002e589b6))
|
||||
* **ApplicationCommand:** stringType isn't supposed to be sent to the API ([#5916](https://github.com/discordjs/discord.js/issues/5916)) ([ca2a36b](https://github.com/discordjs/discord.js/commit/ca2a36b1d713a743045b15adf99eda69a6fdbec7))
|
||||
* **ApplicationCommands:** allow managing commands for uncached guilds ([#5729](https://github.com/discordjs/discord.js/issues/5729)) ([24e5868](https://github.com/discordjs/discord.js/commit/24e586881865c187ff0a3044ac37f6e338cc51ee))
|
||||
* **ClientApplication:** freeze flags ([#5811](https://github.com/discordjs/discord.js/issues/5811)) ([e990c35](https://github.com/discordjs/discord.js/commit/e990c35476fb6f7e1a5449493833140144e0469c))
|
||||
* **Collector:** docs and types ([#5937](https://github.com/discordjs/discord.js/issues/5937)) ([6c447b1](https://github.com/discordjs/discord.js/commit/6c447b12e3f978328cb2577ea3f81a5ab1531bbf))
|
||||
* **Guild:** don't patch before instance properties ([#5885](https://github.com/discordjs/discord.js/issues/5885)) ([174b7a7](https://github.com/discordjs/discord.js/commit/174b7a7f9c5f95ab182a2c90dae43ccd4f55357b))
|
||||
* **Guild:** setChannelPositions null parenting ([#5841](https://github.com/discordjs/discord.js/issues/5841)) ([01a1fd6](https://github.com/discordjs/discord.js/commit/01a1fd615bbf017e18bbffe8e97336345f42564a))
|
||||
* **GuildChannel:** clone errors when options.name isn't provided ([#5804](https://github.com/discordjs/discord.js/issues/5804)) ([41673b7](https://github.com/discordjs/discord.js/commit/41673b738232f64da2ded3b15be0f798135ae351))
|
||||
* **GuildChannel:** don't force parentID/permissionOverwrites to empty on create ([#5823](https://github.com/discordjs/discord.js/issues/5823)) ([c585933](https://github.com/discordjs/discord.js/commit/c5859337b616c1fe2a60884595d27db4f13d8fee))
|
||||
* **GuildChannel:** improve empty overwrite handling for permissionsLocked ([#5821](https://github.com/discordjs/discord.js/issues/5821)) ([6df3623](https://github.com/discordjs/discord.js/commit/6df36232a05e396d31461200725755745526d2ed))
|
||||
* **GuildChannel:** spread clone options to avoid infinite recursion ([#5800](https://github.com/discordjs/discord.js/issues/5800)) ([2f5424b](https://github.com/discordjs/discord.js/commit/2f5424bdac7c97d0a371dd72084ac02d5e774f1a))
|
||||
* **GuildManager:** #create throws when systemChannelFlags is undefined ([#5832](https://github.com/discordjs/discord.js/issues/5832)) ([29173bf](https://github.com/discordjs/discord.js/commit/29173bf814e2cd795467b9b3814f0eaf0773e9ae))
|
||||
* **Hooks:** make husky hooks executable ([#5812](https://github.com/discordjs/discord.js/issues/5812)) ([77e28cf](https://github.com/discordjs/discord.js/commit/77e28cf65b0fb3fc2fb7ab07fc7bb0f2f5a400b5))
|
||||
* **InteractionResponses:** set replied status on editReply ([#5899](https://github.com/discordjs/discord.js/issues/5899)) ([6d3d00b](https://github.com/discordjs/discord.js/commit/6d3d00b44577a70e840f0187d6894043677c5329))
|
||||
* **Message:** editedTimestamp defaulting to 0 ([#5847](https://github.com/discordjs/discord.js/issues/5847)) ([671436c](https://github.com/discordjs/discord.js/commit/671436cbb89f7f48bd9ae0ccb9dd75a376cc5281))
|
||||
* **Message:** flags not being parsed on some edits ([#5886](https://github.com/discordjs/discord.js/issues/5886)) ([2d7c12b](https://github.com/discordjs/discord.js/commit/2d7c12b0e9387f56f1809822bc2c8c4ee52a00e9))
|
||||
* **Message:** Make author of referenced message nullable ([#5929](https://github.com/discordjs/discord.js/issues/5929)) ([dc671c8](https://github.com/discordjs/discord.js/commit/dc671c8ac418c1f932034e82f38def28575a4b65))
|
||||
* **PermissionOverwrites:** optional allow/deny OverwriteData ([#5810](https://github.com/discordjs/discord.js/issues/5810)) ([a7ebb21](https://github.com/discordjs/discord.js/commit/a7ebb2145c380214567514906393c4ab87932e95))
|
||||
* **Permissions:** allow admin to override in the missing method ([#5911](https://github.com/discordjs/discord.js/issues/5911)) ([ee025b0](https://github.com/discordjs/discord.js/commit/ee025b05588493b55057b237ca96f88ecc5f0b02))
|
||||
* **presenceUpdate:** fire when only state/details change on an activity ([#5846](https://github.com/discordjs/discord.js/issues/5846)) ([1f8f3ab](https://github.com/discordjs/discord.js/commit/1f8f3ab0f8dbd346154bbfa14a98726b8df25d57))
|
||||
* **Sharding:** strict type context and return ([#5933](https://github.com/discordjs/discord.js/issues/5933)) ([1925d01](https://github.com/discordjs/discord.js/commit/1925d01d8f05ca10b2a39b91f25ffcabe363874b))
|
||||
* **TextBasedChannel:** allow passing an APIMessage with split ([#5815](https://github.com/discordjs/discord.js/issues/5815)) ([93b0a4e](https://github.com/discordjs/discord.js/commit/93b0a4e005b5b1d371f7936238556db2e36cc982))
|
||||
* **Thread:** make archive_timestamp not nullable ([#5965](https://github.com/discordjs/discord.js/issues/5965)) ([edab5af](https://github.com/discordjs/discord.js/commit/edab5afff9a4c79e5965c7c52b0a0d5ebb9ba35a))
|
||||
* **ThreadChannel:** check for existence of properties when patching ([#5961](https://github.com/discordjs/discord.js/issues/5961)) ([9ac6867](https://github.com/discordjs/discord.js/commit/9ac68670d782fc81e266784e790af699f280eb0e))
|
||||
* **ThreadManager:** fixed wrong private and fetchAll check ([#6012](https://github.com/discordjs/discord.js/issues/6012)) ([e4be666](https://github.com/discordjs/discord.js/commit/e4be666c2c273c56f04b8f965efc88bb9aff0032))
|
||||
* **ThreadMemberManager:** fix ThreadMemberManager#add and ThreadMemberManager#fetch ([#5927](https://github.com/discordjs/discord.js/issues/5927)) ([adecead](https://github.com/discordjs/discord.js/commit/adecead716670278516fd031f240e05792420c75))
|
||||
* **Typings:** erronous RawMessage ([5842e35](https://github.com/discordjs/discord.js/commit/5842e35881755350764b557d66b475c2c03f249a))
|
||||
* **Typings:** Fix BitField toJSON/valueOf return types ([#5806](https://github.com/discordjs/discord.js/issues/5806)) ([935f819](https://github.com/discordjs/discord.js/commit/935f819207ac4219d37f3b99a2508e368626e6da))
|
||||
* **Typings:** Improve components typings in MessageEditOptions ([#6002](https://github.com/discordjs/discord.js/issues/6002)) ([3a718d8](https://github.com/discordjs/discord.js/commit/3a718d8c625ab45bc9f4dfcd9d6bbdef67ae75b4))
|
||||
* **User:** fix bot and system properties being incorrect in some cases ([#5923](https://github.com/discordjs/discord.js/issues/5923)) ([e44ae96](https://github.com/discordjs/discord.js/commit/e44ae961005358dac7032c75bfc74be3b719e5a1))
|
||||
* **Webhook:** resolve non-string avatars too ([#5914](https://github.com/discordjs/discord.js/issues/5914)) ([4714a96](https://github.com/discordjs/discord.js/commit/4714a961b87746b0f85214c756614d276666f285))
|
||||
* **Webhook:** return void from #delete for consistency. ([#5954](https://github.com/discordjs/discord.js/issues/5954)) ([5ad83a6](https://github.com/discordjs/discord.js/commit/5ad83a6a65e5944ceb3a41fee2df40ba1f5b03e4))
|
||||
* **Webhook:** throw an error if no token is available when it's required ([#5798](https://github.com/discordjs/discord.js/issues/5798)) ([eb98e33](https://github.com/discordjs/discord.js/commit/eb98e33a85cc9bb235ceb509ed01218bae44ba73))
|
||||
* **WebSocketShard:** don't catch errors thrown in event handlers ([#5803](https://github.com/discordjs/discord.js/issues/5803)) ([53d8e49](https://github.com/discordjs/discord.js/commit/53d8e49dca2d83fe2e066fb0b3d10418acbbc244))
|
||||
* don't patch missing properties from partial payloads ([#5796](https://github.com/discordjs/discord.js/issues/5796)) ([097c7b9](https://github.com/discordjs/discord.js/commit/097c7b9cdd5e1bb52b037272eed19f556800ccff))
|
||||
* add missing imports for custom errors ([#5767](https://github.com/discordjs/discord.js/issues/5767)) ([e980948](https://github.com/discordjs/discord.js/commit/e980948de55e91e59c9e3293ac76bc645a058a53))
|
||||
* **ApiMessage:** only pass objects as options directly ([#5793](https://github.com/discordjs/discord.js/issues/5793)) ([3578159](https://github.com/discordjs/discord.js/commit/35781597d032fa7821e010e483c89f70ec51926c))
|
||||
* **BitField:** ensure missing returns an array of strings ([#5795](https://github.com/discordjs/discord.js/issues/5795)) ([68f7aeb](https://github.com/discordjs/discord.js/commit/68f7aebcafcfd62bef02de855ca0c304a54e8d4c))
|
||||
* **BitField:** throw an error if bit to resolve is undefined ([#5565](https://github.com/discordjs/discord.js/issues/5565)) ([0156f69](https://github.com/discordjs/discord.js/commit/0156f693e08fe2ad75133bf67c4aeb3e9c91a02d))
|
||||
* **ClientPresence:** produce valid activities for set presences ([#5799](https://github.com/discordjs/discord.js/issues/5799)) ([ea0e06f](https://github.com/discordjs/discord.js/commit/ea0e06f9802fb57b41f471413b39ccd09546bb67))
|
||||
* add components to MessageOption typedefs ([#5768](https://github.com/discordjs/discord.js/issues/5768)) ([657635c](https://github.com/discordjs/discord.js/commit/657635c1c09aa68211130bc3c56d6e8bb6e8e773))
|
||||
* remove remnants of awaitMessageComponentInteractions ([#5783](https://github.com/discordjs/discord.js/issues/5783)) ([ae78a33](https://github.com/discordjs/discord.js/commit/ae78a336e1d0d190ec9f525449332dc781e0b3bf))
|
||||
* **APIMessage:** document Interaction as valid MessageTarget ([#5678](https://github.com/discordjs/discord.js/issues/5678)) ([9f491ff](https://github.com/discordjs/discord.js/commit/9f491ffeb96ff380f2ab5ab2f86201d58be64c41))
|
||||
* **ApplicationCommand:** return string equivalent of ApplicationCommandOptionType ([#5617](https://github.com/discordjs/discord.js/issues/5617)) ([a6079bc](https://github.com/discordjs/discord.js/commit/a6079bc9ce40ecbb4adace033dbf201897b5459f))
|
||||
* **ApplicationCommandManager:** fix typo in JSDoc ([#5603](https://github.com/discordjs/discord.js/issues/5603)) ([3392eb7](https://github.com/discordjs/discord.js/commit/3392eb7de270842dbf5a54d19aa3e703dd445ba0))
|
||||
* **ApplicationCommandManager:** limit permission methods to guilds ([#5613](https://github.com/discordjs/discord.js/issues/5613)) ([03256bd](https://github.com/discordjs/discord.js/commit/03256bd9f88c63dc5c2169e2c09ac8078ea84992))
|
||||
* **ApplicationCommandOptionData:** options property should be itself ([#5679](https://github.com/discordjs/discord.js/issues/5679)) ([b90b0c3](https://github.com/discordjs/discord.js/commit/b90b0c3cfa2278caa38d1ff41eef2ccf4428b99e))
|
||||
* **CommandInteraction:** channel type should be text based channels ([#5690](https://github.com/discordjs/discord.js/issues/5690)) ([5141ea4](https://github.com/discordjs/discord.js/commit/5141ea4f0694a60375d8bc0801b1225928bb3bd1))
|
||||
* **CommandInteraction:** cmds with no options throw error ([#5734](https://github.com/discordjs/discord.js/issues/5734)) ([af2fad9](https://github.com/discordjs/discord.js/commit/af2fad94732eeb620fe17d9b537c279471c567c0))
|
||||
* **CommandInteraction:** update typings and docs for #editReply ([#5630](https://github.com/discordjs/discord.js/issues/5630)) ([56d44fb](https://github.com/discordjs/discord.js/commit/56d44fbf1c922260c497350e8829d7151eb7a331))
|
||||
* **DataResolver:** fix circular dependency error with GuildTemplate ([#5622](https://github.com/discordjs/discord.js/issues/5622)) ([b376f31](https://github.com/discordjs/discord.js/commit/b376f31af9881b9cd3f82ac4a42a468947cce482))
|
||||
* **Emoji:** name can be null ([#5513](https://github.com/discordjs/discord.js/issues/5513)) ([5397021](https://github.com/discordjs/discord.js/commit/5397021efb1f9883cf4b48a0ca78d12b713a61fd))
|
||||
* **GuildEmojiRoleManager:** bug in #remove ([#5666](https://github.com/discordjs/discord.js/issues/5666)) ([c89bdd7](https://github.com/discordjs/discord.js/commit/c89bdd7566599a95a404b0f9e4b0828a866d0a71))
|
||||
* **GuildMemberManager:** allow moving members to any non-text channel ([#5681](https://github.com/discordjs/discord.js/issues/5681)) ([d21e6af](https://github.com/discordjs/discord.js/commit/d21e6af1d2b81db9847336b3f964f9d2693394e6))
|
||||
* **GuildMemberRoleManager:** unable to remove roles when passed an array ([#5556](https://github.com/discordjs/discord.js/issues/5556)) ([9572521](https://github.com/discordjs/discord.js/commit/9572521e3c390e610de8e4dc79e4086b3b1d6e44))
|
||||
* **HTTPOptions:** change default value in jsdoc to 8 ([#5547](https://github.com/discordjs/discord.js/issues/5547)) ([cb50241](https://github.com/discordjs/discord.js/commit/cb50241e6fa7c95891925c8b18840c17df078620))
|
||||
* **Interaction:** add missing types and fix docs lists ([#5762](https://github.com/discordjs/discord.js/issues/5762)) ([1d57754](https://github.com/discordjs/discord.js/commit/1d57754d4654c5c95aa14afc13f8abe335314767))
|
||||
* **Message:** bug in #suppressEmbeds due to [#5612](https://github.com/discordjs/discord.js/issues/5612) ([#5644](https://github.com/discordjs/discord.js/issues/5644)) ([840ad0a](https://github.com/discordjs/discord.js/commit/840ad0a35a344a19c5bb84c421f80802fb186d0b))
|
||||
* **Message:** editing with MessageEmbed or APIMessage ([#5612](https://github.com/discordjs/discord.js/issues/5612)) ([74e97ef](https://github.com/discordjs/discord.js/commit/74e97ef91b413300c83f163bc3914eaf8bd45d89))
|
||||
* **Message:** update typings and docs related to #edit ([#5745](https://github.com/discordjs/discord.js/issues/5745)) ([a2f0c11](https://github.com/discordjs/discord.js/commit/a2f0c11474826bfd5b770d2a6990b6bd41c89451))
|
||||
* **MessageComponentInteraction:** correctly type defer method ([#5760](https://github.com/discordjs/discord.js/issues/5760)) ([f0dad26](https://github.com/discordjs/discord.js/commit/f0dad26a5b8c3139b2519d1895df2fe23352b102))
|
||||
* **MessageEmbed:** import custom RangeError class ([#5740](https://github.com/discordjs/discord.js/issues/5740)) ([bfe01b5](https://github.com/discordjs/discord.js/commit/bfe01b52ab29df1bb26fc2d385f63fb5adbb12b2))
|
||||
* **PermissionOverwrites:** fix typo in typedef jsdoc ([#5704](https://github.com/discordjs/discord.js/issues/5704)) ([6567ba8](https://github.com/discordjs/discord.js/commit/6567ba821a54d3dc97d07ce8ac55335fef2f346b))
|
||||
* **RoleManager:** bug in #create ([#5730](https://github.com/discordjs/discord.js/issues/5730)) ([cf22456](https://github.com/discordjs/discord.js/commit/cf224560bc59c05f7801088b0db2ec76c5369302))
|
||||
* **ShardingManager:** client error event cannot be emitted ([#5559](https://github.com/discordjs/discord.js/issues/5559)) ([d1c5b6f](https://github.com/discordjs/discord.js/commit/d1c5b6fe9e18b532ad69ed4bd82e1874a6dff4df))
|
||||
* **Types:** make event listeners accept async callbacks ([#5602](https://github.com/discordjs/discord.js/issues/5602)) ([a73a5cf](https://github.com/discordjs/discord.js/commit/a73a5cf91498cf7b08cea85753ad481c194ec089))
|
||||
* **Typings:** add missing typings for `HttpError` -> `requestData` ([#5742](https://github.com/discordjs/discord.js/issues/5742)) ([3e9ce35](https://github.com/discordjs/discord.js/commit/3e9ce35023e71ffda1f4eaca6f109b0422ec7d29))
|
||||
* **Webhook:** #editMessage throws error when content is null ([#5757](https://github.com/discordjs/discord.js/issues/5757)) ([2901fd5](https://github.com/discordjs/discord.js/commit/2901fd595be847a0e6c86155b3229d3341cfad32))
|
||||
* interfaces not importing due to re-export of Snowflake ([#5723](https://github.com/discordjs/discord.js/issues/5723)) ([086c3f0](https://github.com/discordjs/discord.js/commit/086c3f0799d65c64c4e60d6370246a37a27a1eab))
|
||||
* lint-staged for typescript files ([5f6ec22](https://github.com/discordjs/discord.js/commit/5f6ec2211d1e6555ab2d501579e4a1d97023c647))
|
||||
* resolve emoji in Message#react ([#5614](https://github.com/discordjs/discord.js/issues/5614)) ([c733436](https://github.com/discordjs/discord.js/commit/c7334363b36c5f7f1c7880fe77a2e9b2eb1a6442))
|
||||
* typo in GuildMemberManager ([#5616](https://github.com/discordjs/discord.js/issues/5616)) ([73f4114](https://github.com/discordjs/discord.js/commit/73f4114f59fc2f514d570ac8df3eac7d328cca3c))
|
||||
* **Sticker:** file renamed to SnowflakeUtil ([#5573](https://github.com/discordjs/discord.js/issues/5573)) ([f830eb7](https://github.com/discordjs/discord.js/commit/f830eb7101d05f90bbbf44ff750e4012ecb72449))
|
||||
* **VoiceReceiver:** fix memory leak ([#5609](https://github.com/discordjs/discord.js/issues/5609)) ([2eac842](https://github.com/discordjs/discord.js/commit/2eac84296b448907213680690ec766bb5fbe5990))
|
||||
* typings for 'Message' ([#5518](https://github.com/discordjs/discord.js/issues/5518)) ([0d68ca8](https://github.com/discordjs/discord.js/commit/0d68ca8eb9abdb517acee562fe01374416d225ed))
|
||||
* **ApiMessage:** remove resolve() from typings ([#5241](https://github.com/discordjs/discord.js/issues/5241)) ([a6bc39d](https://github.com/discordjs/discord.js/commit/a6bc39d3c699eec0b7851cda334335baa892c1de))
|
||||
* **ApplicationFlags:** export class ([#5465](https://github.com/discordjs/discord.js/issues/5465)) ([404ce57](https://github.com/discordjs/discord.js/commit/404ce57bcc3ce39c807457f25a5679a80e69d1bb))
|
||||
* **BaseGuildEmoji:** typo in requiresColons ([#5076](https://github.com/discordjs/discord.js/issues/5076)) ([e272fd6](https://github.com/discordjs/discord.js/commit/e272fd6909a17941d2d3e4840e75436d98a41198))
|
||||
* **ChannelManager:** Avoid crash in remove method with uncached channel ([#4937](https://github.com/discordjs/discord.js/issues/4937)) ([12c909e](https://github.com/discordjs/discord.js/commit/12c909eeccb9ed6ab205d314ac8d63fc58713ae6))
|
||||
* **Collection:** toJSON() errors if the collection includes empty values ([#5129](https://github.com/discordjs/discord.js/issues/5129)) ([2c2249e](https://github.com/discordjs/discord.js/commit/2c2249ee7314401b65be677c233370657e1d4695))
|
||||
* **Collector:** throw an error if a non-function was provided as filter ([#5034](https://github.com/discordjs/discord.js/issues/5034)) ([7365f40](https://github.com/discordjs/discord.js/commit/7365f403006eeb28ab10f03cbf85416272678ef7))
|
||||
* **Guild/GuildChannel:** methods reason arg usage ([#5419](https://github.com/discordjs/discord.js/issues/5419)) ([8411b9e](https://github.com/discordjs/discord.js/commit/8411b9e14211f83fddb00f622088979ee6586803))
|
||||
* **GuildAuditLogsEntry:** executor can be missing ([#5500](https://github.com/discordjs/discord.js/issues/5500)) ([e9bf206](https://github.com/discordjs/discord.js/commit/e9bf206d88b9307e4098b7f89178105d08b07544))
|
||||
* **GuildChannel:** check for community required channels in GuildChannel#deletable ([#5170](https://github.com/discordjs/discord.js/issues/5170)) ([b710a43](https://github.com/discordjs/discord.js/commit/b710a432326be823beb10f5f06f2a1e3fcd7c0ee))
|
||||
* **GuildChannel:** overload permissionsFor and BaseManager#resolve[id] ([#5260](https://github.com/discordjs/discord.js/issues/5260)) ([41bd6c2](https://github.com/discordjs/discord.js/commit/41bd6c2717faeeaa36514d39a4816f7cf65b4c02))
|
||||
* **GuildChannel:** regression on default channel type ([#5251](https://github.com/discordjs/discord.js/issues/5251)) ([e7c4f36](https://github.com/discordjs/discord.js/commit/e7c4f3672e7059c264ba67a94b87a655ea6e4da5))
|
||||
* **GuildEmoji:** check for cahnges to available in equals ([#5201](https://github.com/discordjs/discord.js/issues/5201)) ([f95f5dc](https://github.com/discordjs/discord.js/commit/f95f5dcd791b39c6a4d60dc8d64b0287e06ed768))
|
||||
* **GuildManager:** add missing toString() on Permission#resolve fns ([#5324](https://github.com/discordjs/discord.js/issues/5324)) ([0778926](https://github.com/discordjs/discord.js/commit/077892645bd59d1b5c50e3291701cb4241c0bbdf))
|
||||
* **GuildMember:** correctly check for premium_since ([#5312](https://github.com/discordjs/discord.js/issues/5312)) ([aff3625](https://github.com/discordjs/discord.js/commit/aff3625d4fc3c738d77325f8492b72077e6345e7))
|
||||
* **GuildTemplate:** 'guild' getter ([#5040](https://github.com/discordjs/discord.js/issues/5040)) ([53529bd](https://github.com/discordjs/discord.js/commit/53529bd05deb449d5d9bbfa332470c9881d8093c))
|
||||
* **IntegrationApplication:** add missing export to index.js ([#5475](https://github.com/discordjs/discord.js/issues/5475)) ([8023250](https://github.com/discordjs/discord.js/commit/8023250ee7bb79a5e3f12d7297c29589f91d6b81))
|
||||
* **InviteDelete:** guild can be missing ([#5457](https://github.com/discordjs/discord.js/issues/5457)) ([6c6b105](https://github.com/discordjs/discord.js/commit/6c6b1053b7a6778a5d0402941a13258ca13378f8))
|
||||
* **Message:** #system non-zero message types are not guaranteed to be system ([#5108](https://github.com/discordjs/discord.js/issues/5108)) ([bb78120](https://github.com/discordjs/discord.js/commit/bb78120283b671d1926c8707a17a9d4d515aafdd))
|
||||
* **Message:** update getters to take null permissions into account ([#5066](https://github.com/discordjs/discord.js/issues/5066)) ([98b1c58](https://github.com/discordjs/discord.js/commit/98b1c582189faee9ac40d81963008d94801f3837))
|
||||
* **MessageEmbed:** include `author.name` in length getter ([#5167](https://github.com/discordjs/discord.js/issues/5167)) ([e37160f](https://github.com/discordjs/discord.js/commit/e37160f4e3d647e8e33b5b03d5f9e6c98b065499))
|
||||
* **MessageMentions#channels:** Fix type of channels of mentions ([#5370](https://github.com/discordjs/discord.js/issues/5370)) ([565d7b3](https://github.com/discordjs/discord.js/commit/565d7b3747d59ceeb01e2d88b20d761a99927a12))
|
||||
* **MessageReaction:** set MessageReaction#me in patch method ([#5047](https://github.com/discordjs/discord.js/issues/5047)) ([6b322f4](https://github.com/discordjs/discord.js/commit/6b322f47a0f86115dab71c06c7879fe82ea04ec4))
|
||||
* **ReactionUserManager:** remove before query option ([#5281](https://github.com/discordjs/discord.js/issues/5281)) ([43bd568](https://github.com/discordjs/discord.js/commit/43bd568f1c38a6df38f56a8d607375ccc9da026a))
|
||||
* **Resolvables:** valid resolvables throw error when uncached ([#5495](https://github.com/discordjs/discord.js/issues/5495)) ([fa5a37e](https://github.com/discordjs/discord.js/commit/fa5a37e51a14fdd95420092fb8c2acffad132c3b))
|
||||
* **Role:** pass Permissions class, not the bitfield ([#5321](https://github.com/discordjs/discord.js/issues/5321)) ([d744e51](https://github.com/discordjs/discord.js/commit/d744e51c1bdb4c7a26c0faeea1f2f45baaf5fd3c))
|
||||
* **RoleManager:** fix ID return value, change return type to collection ([#4935](https://github.com/discordjs/discord.js/issues/4935)) ([12a096b](https://github.com/discordjs/discord.js/commit/12a096b5f1c5ad518e73d1b9f50bb388928117dd))
|
||||
* **typings:** return types for 'Webhook(Client)#send()' ([#4876](https://github.com/discordjs/discord.js/issues/4876)) ([eb28ee7](https://github.com/discordjs/discord.js/commit/eb28ee7905eee248b9ccd248f7d8275933dd0637))
|
||||
* **typings:** update GuildMemberRoleManager typings to match implementation ([#5497](https://github.com/discordjs/discord.js/issues/5497)) ([900e576](https://github.com/discordjs/discord.js/commit/900e57657e80833df2557c60862fcd71b35d0df1))
|
||||
* **UserFlags:** correct early bot dev name, remove deprecated aliases ([#5104](https://github.com/discordjs/discord.js/issues/5104)) ([b509862](https://github.com/discordjs/discord.js/commit/b509862bfa924494824af5e7729bd545315d2c67))
|
||||
* **Voice:** disconnect if voice channel not cached ([#5467](https://github.com/discordjs/discord.js/issues/5467)) ([3af8179](https://github.com/discordjs/discord.js/commit/3af8179878c093985c8a94ee2fd7e99d45243bda))
|
||||
* **Voice:** only skip undocumented voice packet byte if present ([#5309](https://github.com/discordjs/discord.js/issues/5309)) ([2b52cdc](https://github.com/discordjs/discord.js/commit/2b52cdc915146c6775bc7565e5ecf31e7c9880e7))
|
||||
* add presence to ClientPresence from ClientOptions ([#5041](https://github.com/discordjs/discord.js/issues/5041)) ([9c7fe34](https://github.com/discordjs/discord.js/commit/9c7fe34c50808ba080527a1919b1846ed6585d4d))
|
||||
* filtering of string forms of null and undefined ([#5075](https://github.com/discordjs/discord.js/issues/5075)) ([9042d19](https://github.com/discordjs/discord.js/commit/9042d19c4ef54d9976776f41336610ab0a24db27))
|
||||
* implement valueOf on pseudomanagers ([#4595](https://github.com/discordjs/discord.js/issues/4595)) ([8883a01](https://github.com/discordjs/discord.js/commit/8883a0144b02e76c767c21ecf28fb430b7223c7f))
|
||||
* typings for 'WebhookMessageOptions' ([#5476](https://github.com/discordjs/discord.js/issues/5476)) ([67025e6](https://github.com/discordjs/discord.js/commit/67025e63e4e8306a2b3ff62ae1067acf4b468a6a))
|
||||
* **Voice*:** filter out silent audio from video users ([#5035](https://github.com/discordjs/discord.js/issues/5035)) ([4fcb9eb](https://github.com/discordjs/discord.js/commit/4fcb9ebf300633022e2b9867fa06a586307ff17a))
|
||||
* **VoiceConnection:** make #dispatcher nullable ([#5217](https://github.com/discordjs/discord.js/issues/5217)) ([0d5de43](https://github.com/discordjs/discord.js/commit/0d5de4333d8afa57826aa75475fc4e3dfe8978c4))
|
||||
* **WebSocketShard:** key name in WebSocketShard#_send. ([#5304](https://github.com/discordjs/discord.js/issues/5304)) ([56d8b44](https://github.com/discordjs/discord.js/commit/56d8b445ede6c7915aec173a68905cda3d91f0ca)), closes [#3722](https://github.com/discordjs/discord.js/issues/3722)
|
||||
|
||||
|
||||
### Code Refactoring
|
||||
|
||||
* removed `code` and `split` options ([#5918](https://github.com/discordjs/discord.js/issues/5918)) ([985d4d6](https://github.com/discordjs/discord.js/commit/985d4d6a438fc9123264f6a1c600f34fccc1825f))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **ApplicationCommandOptionType:** add NUMBER (10) ([#6128](https://github.com/discordjs/discord.js/issues/6128)) ([2f1cc1f](https://github.com/discordjs/discord.js/commit/2f1cc1fc27f5af6d9b88cdc353605a3ddf76e579))
|
||||
* **Channel:** add isThread typeguard for better TS support ([#5978](https://github.com/discordjs/discord.js/issues/5978)) ([b7ed675](https://github.com/discordjs/discord.js/commit/b7ed6752ac98e56e79b6fd9fd3a5e47572454d85))
|
||||
* **Channel:** add isVoice() ([#6297](https://github.com/discordjs/discord.js/issues/6297)) ([5b4efd1](https://github.com/discordjs/discord.js/commit/5b4efd13c9eced97f4160f9c4c19d1c843360943))
|
||||
* **Client:** add conditional ready typings ([#6073](https://github.com/discordjs/discord.js/issues/6073)) ([4206e35](https://github.com/discordjs/discord.js/commit/4206e35b2316431c1a009664636dcda85d39fff8))
|
||||
* **Client:** enforce passing scopes to generateInvite ([#6024](https://github.com/discordjs/discord.js/issues/6024)) ([c6e5521](https://github.com/discordjs/discord.js/commit/c6e55216874f1892727db927f55db3de6a1712d8))
|
||||
* **Collector:** better types for events ([#6058](https://github.com/discordjs/discord.js/issues/6058)) ([c0a814f](https://github.com/discordjs/discord.js/commit/c0a814fdb35cb1fa7418bb3bdd3cec0a8a130bf5))
|
||||
* **Collector:** return a boolean on checkEnd ([#6289](https://github.com/discordjs/discord.js/issues/6289)) ([f473f43](https://github.com/discordjs/discord.js/commit/f473f43d081c8c703a0888acaf3fdbaf4bb20c6d))
|
||||
* **CommandInteraction:** add CommandInteractionOptionResolver ([#6107](https://github.com/discordjs/discord.js/issues/6107)) ([f293132](https://github.com/discordjs/discord.js/commit/f293132345294e33e80866272feaedf2e4a70d45))
|
||||
* **CommandInteractionOptionResolver:** add sub-command required option ([#6165](https://github.com/discordjs/discord.js/issues/6165)) ([690c121](https://github.com/discordjs/discord.js/commit/690c121aa9575f7b878030229b0fedd56c3a1a87))
|
||||
* **Constants:** added more error codes ([#6234](https://github.com/discordjs/discord.js/issues/6234)) ([6b2098f](https://github.com/discordjs/discord.js/commit/6b2098f7c7592eee2aedbf19e62d3c262e159cba))
|
||||
* **FetchRecommendedShardsOptions:** account for large bot sharding ([#6184](https://github.com/discordjs/discord.js/issues/6184)) ([19b242a](https://github.com/discordjs/discord.js/commit/19b242ac10aa9b32c1a45a9178c97481d62a9400))
|
||||
* **Formatters:** added new URL utilities and docs ([#6014](https://github.com/discordjs/discord.js/issues/6014)) ([98e45a5](https://github.com/discordjs/discord.js/commit/98e45a59957842fd1ee55d59e30ee868f985e15d))
|
||||
* **Guild:** add fetchWidget() for getting widget data ([#6180](https://github.com/discordjs/discord.js/issues/6180)) ([b22272f](https://github.com/discordjs/discord.js/commit/b22272f86075ac5585abf05f54cf05187c4eabf9))
|
||||
* **GuildAuditLogs:** add threads ([#6195](https://github.com/discordjs/discord.js/issues/6195)) ([26ba0e1](https://github.com/discordjs/discord.js/commit/26ba0e10368ff7c4b7a79a37450c8c0784185fb7))
|
||||
* **GuildPreview:** add createdAt & createdTimestamp ([#6130](https://github.com/discordjs/discord.js/issues/6130)) ([9f039a8](https://github.com/discordjs/discord.js/commit/9f039a86798352e360d7e47d62d1b9c011c2ec71))
|
||||
* **InteractionCollector:** reworked to be more generic ([#5999](https://github.com/discordjs/discord.js/issues/5999)) ([374c779](https://github.com/discordjs/discord.js/commit/374c779f7f8bbaa9bf06fa2b5b16f60da5095b5c))
|
||||
* **Interactions:** option to auto-fetch replies ([#5831](https://github.com/discordjs/discord.js/issues/5831)) ([5e28ff8](https://github.com/discordjs/discord.js/commit/5e28ff83cbc04850077cc2f97bb2039c55b3b8ea))
|
||||
* **LimitedCollection:** export LimitedCollection ([#6043](https://github.com/discordjs/discord.js/issues/6043)) ([31d3129](https://github.com/discordjs/discord.js/commit/31d31293d314492562104f02511d4d1e117711f3))
|
||||
* **Managers:** ✨ Add GuildInviteManager ([#5889](https://github.com/discordjs/discord.js/issues/5889)) ([9e08b02](https://github.com/discordjs/discord.js/commit/9e08b02df2c9b31cfd91eac3ad008dab94855a59))
|
||||
* **Managers:** add customizable caching for managers ([#6013](https://github.com/discordjs/discord.js/issues/6013)) ([8c7cb0e](https://github.com/discordjs/discord.js/commit/8c7cb0eff8e169836decf3c9843d7fa0998a5e84))
|
||||
* **Message:** add 'failIfNotExists' to ClientOptions ([#6038](https://github.com/discordjs/discord.js/issues/6038)) ([28c5724](https://github.com/discordjs/discord.js/commit/28c57246d1d3cd7a22384ddc7970ab5263a4ace0))
|
||||
* **MessageEmbed:** add setFields method ([#6186](https://github.com/discordjs/discord.js/issues/6186)) ([a25e165](https://github.com/discordjs/discord.js/commit/a25e16599a2b3d82aabebcaeaef663680f2982a8))
|
||||
* **REST:** append additional information to the required User Agent ([#6112](https://github.com/discordjs/discord.js/issues/6112)) ([f200f14](https://github.com/discordjs/discord.js/commit/f200f14a409a56df5efe788de0ae45fc061bb46d))
|
||||
* **RoleManager:** added `edit` method, alias `Role#edit` ([#5983](https://github.com/discordjs/discord.js/issues/5983)) ([1e73c25](https://github.com/discordjs/discord.js/commit/1e73c25fbfc9b3cb62bed719dc79de25f67707ee))
|
||||
* **StageChannel:** add createStageInstance method & use better naming convention ([#5951](https://github.com/discordjs/discord.js/issues/5951)) ([71fb33a](https://github.com/discordjs/discord.js/commit/71fb33a5fea7398598b603a888e07519fddd56a9))
|
||||
* **Sticker:** updates, sticker packs, and guild stickers ([#5867](https://github.com/discordjs/discord.js/issues/5867)) ([54d6a3a](https://github.com/discordjs/discord.js/commit/54d6a3a0708105acd6a3a709a8e1636d00c81fc8))
|
||||
* **ThreadChannel:** add fetchOwner() method ([#6207](https://github.com/discordjs/discord.js/issues/6207)) ([331a9d3](https://github.com/discordjs/discord.js/commit/331a9d3ffc6e45c068bfb454e05b863130559d42))
|
||||
* **Util:** add SweptCollection for auto sweeping of caches ([#6110](https://github.com/discordjs/discord.js/issues/6110)) ([dbb59ba](https://github.com/discordjs/discord.js/commit/dbb59ba1b29b2f75dd8faab5c3004ade51598abc))
|
||||
* **Util:** added formatters ([#5976](https://github.com/discordjs/discord.js/issues/5976)) ([8c7a28f](https://github.com/discordjs/discord.js/commit/8c7a28f211dd05ec67cbce667b1d591ed59a40c6))
|
||||
* **WebhookClient:** allow creation of clients via URLs ([#6192](https://github.com/discordjs/discord.js/issues/6192)) ([e000af5](https://github.com/discordjs/discord.js/commit/e000af5c98483046db25a46e905ed244bdcfe262))
|
||||
* allow channels from uncached guilds to be returned from fetch ([#6034](https://github.com/discordjs/discord.js/issues/6034)) ([755c180](https://github.com/discordjs/discord.js/commit/755c180659c125532fe6f8e33e6c3b56e275311b))
|
||||
* make Instance#fetch force true by default, and fix force parameter ([#6116](https://github.com/discordjs/discord.js/issues/6116)) ([366f3c9](https://github.com/discordjs/discord.js/commit/366f3c910a370ff1e184afae054f957db9a98293))
|
||||
* PermissionOverwriteManager ([#5318](https://github.com/discordjs/discord.js/issues/5318)) ([e7ad2fe](https://github.com/discordjs/discord.js/commit/e7ad2fe20772915dcf3e9c4ae92a072b9c918a07))
|
||||
* use enums for consistency and speed ([#5843](https://github.com/discordjs/discord.js/issues/5843)) ([f7eeccb](https://github.com/discordjs/discord.js/commit/f7eeccba4b7015496df811f10cc2da2b0fab0630))
|
||||
* **Client:** make use of with_expiration in #fetchInvite ([#5764](https://github.com/discordjs/discord.js/issues/5764)) ([bf191df](https://github.com/discordjs/discord.js/commit/bf191df9c033404da3e717f73306cdb3f659fafc))
|
||||
* **Esm:** use `gen-esm-wrapper` instead of manually making the file ([#5700](https://github.com/discordjs/discord.js/issues/5700)) ([db0d7d4](https://github.com/discordjs/discord.js/commit/db0d7d4ea8e7b2bae4d1548e5617875b5ae0bbd4))
|
||||
* **Interaction:** add guild guard ([#5955](https://github.com/discordjs/discord.js/issues/5955)) ([87e8cdd](https://github.com/discordjs/discord.js/commit/87e8cdd3eba29ae1d741aa86572f1731b05c12fb))
|
||||
* **Managers:** new ApplicationCommandPermissionsManager ([#5897](https://github.com/discordjs/discord.js/issues/5897)) ([6264c60](https://github.com/discordjs/discord.js/commit/6264c60e97da93b311a7a9fd92e16e59de94104a))
|
||||
* **MessageComponentInteraction:** component getter ([#5840](https://github.com/discordjs/discord.js/issues/5840)) ([1439183](https://github.com/discordjs/discord.js/commit/1439183ad3f84b2b7500aaead2cf8779199b47d4))
|
||||
* **MessageMentions:** add repliedUser ([#5905](https://github.com/discordjs/discord.js/issues/5905)) ([2616125](https://github.com/discordjs/discord.js/commit/261612596d37aa6fb48ae070d358b3fde953c769))
|
||||
* **MessageSelectMenu:** droppybois ([#5692](https://github.com/discordjs/discord.js/issues/5692)) ([e5fcf0b](https://github.com/discordjs/discord.js/commit/e5fcf0bee53a15d7a87d4a5cf4e206823d6e7d87))
|
||||
* api v9 and threads ([#5570](https://github.com/discordjs/discord.js/issues/5570)) ([7346621](https://github.com/discordjs/discord.js/commit/7346621d15c96906d5b848c483669750ff9c6e12))
|
||||
* **InteractionCreate:** move to an Action handler ([#5906](https://github.com/discordjs/discord.js/issues/5906)) ([ea49f7c](https://github.com/discordjs/discord.js/commit/ea49f7ca74892495dd53f8d315086035c1814149))
|
||||
* add missing APIError codes ([#5898](https://github.com/discordjs/discord.js/issues/5898)) ([d930c81](https://github.com/discordjs/discord.js/commit/d930c812bb4511a688b76d9bf1ac66e28bff033e))
|
||||
* **GuildChannelManager:** add 'fetch' method ([#4966](https://github.com/discordjs/discord.js/issues/4966)) ([e798fb7](https://github.com/discordjs/discord.js/commit/e798fb720ee5ced008471fe899337f6817936770))
|
||||
* **Interactions:** add InteractionWebhook for better internals ([#5712](https://github.com/discordjs/discord.js/issues/5712)) ([dec191a](https://github.com/discordjs/discord.js/commit/dec191aa1e4f22690285ca06c6eee7e6086b2930))
|
||||
* **Interactions:** improve error handling for ephemeral responses ([#5892](https://github.com/discordjs/discord.js/issues/5892)) ([bd9f56a](https://github.com/discordjs/discord.js/commit/bd9f56af9a0a1fb12cfa30d9e2e0ad680eb80949))
|
||||
* add APIError codes for stage instance ([#5888](https://github.com/discordjs/discord.js/issues/5888)) ([c850ae1](https://github.com/discordjs/discord.js/commit/c850ae10270076c4b2e10b130dd8f88eed4ed201))
|
||||
* **Message:** applicationID for interaction responses ([#5765](https://github.com/discordjs/discord.js/issues/5765)) ([65dc00f](https://github.com/discordjs/discord.js/commit/65dc00f3210065015684b6d585f6747bd5ebadf1))
|
||||
* **MessageComponents:** clickybois (MessageButton, MessageActionRow, associated Collectors) ([#5674](https://github.com/discordjs/discord.js/issues/5674)) ([cbd7f2b](https://github.com/discordjs/discord.js/commit/cbd7f2b9aa44a9240947ed716d0e72257ac499f7))
|
||||
* **Rest:** optional ratelimit errors ([#5659](https://github.com/discordjs/discord.js/issues/5659)) ([16f261e](https://github.com/discordjs/discord.js/commit/16f261e773a353c54a75f38008f9b28435ae6603))
|
||||
* **Sharding*:** contexts for broadcastEval ([#5756](https://github.com/discordjs/discord.js/issues/5756)) ([c6aeebb](https://github.com/discordjs/discord.js/commit/c6aeebb18d6b969f7c8bdb1b719883d4384dd03e))
|
||||
* **WelcomeScreen:** welcome screens ([#5490](https://github.com/discordjs/discord.js/issues/5490)) ([44e2ee7](https://github.com/discordjs/discord.js/commit/44e2ee7b20dbec79c993dbc1f30ddb643d943347))
|
||||
* stage instance invite ([#5856](https://github.com/discordjs/discord.js/issues/5856)) ([2d12db0](https://github.com/discordjs/discord.js/commit/2d12db000f2a0a22a8919d7a63989a6e762ae335))
|
||||
* document and support embeds field in message create endpoint ([#5792](https://github.com/discordjs/discord.js/issues/5792)) ([99ff715](https://github.com/discordjs/discord.js/commit/99ff7151379fe03a1cfd52f252c0e6fc892d7776))
|
||||
* **Guild:** add enum for mfa_level ([#5797](https://github.com/discordjs/discord.js/issues/5797)) ([ffabec3](https://github.com/discordjs/discord.js/commit/ffabec3a5e3651e5a0b8bcac83ee26bb909695fa))
|
||||
* **Guild:** add enum for premium_tier ([#5868](https://github.com/discordjs/discord.js/issues/5868)) ([a3cbcca](https://github.com/discordjs/discord.js/commit/a3cbcca13da1af416c219bd64a0a6e84bb87a057))
|
||||
* **GuildAuditLogs:** make #target a channel for channel related logs ([#5781](https://github.com/discordjs/discord.js/issues/5781)) ([eb0291d](https://github.com/discordjs/discord.js/commit/eb0291d9a5078836183c1b63ea96461ec112f96e))
|
||||
* **RequestHandler:** emit more info when a rate limit was hit ([#5801](https://github.com/discordjs/discord.js/issues/5801)) ([18ac72e](https://github.com/discordjs/discord.js/commit/18ac72e457fa137d7f7f7bde876436ff643b4a63))
|
||||
* **Widget:** wrapper for widget.json ([#5619](https://github.com/discordjs/discord.js/issues/5619)) ([038ee99](https://github.com/discordjs/discord.js/commit/038ee99604cded41d4c67edf4bd6bc7969712f52))
|
||||
* add new APIErrors ([#5794](https://github.com/discordjs/discord.js/issues/5794)) ([e0ab836](https://github.com/discordjs/discord.js/commit/e0ab836b2d88caf0d9e1f9eba76ae46be9df0554))
|
||||
* enforce strings ([#4880](https://github.com/discordjs/discord.js/issues/4880)) ([7b85a72](https://github.com/discordjs/discord.js/commit/7b85a7259f563ab14ae6c0a665a3dd43c486fde4))
|
||||
* **APIRequest:** support setting global headers in HTTPOptions ([#5586](https://github.com/discordjs/discord.js/issues/5586)) ([135abcc](https://github.com/discordjs/discord.js/commit/135abccd9c75c33c8510cdcbe33b0dea4198fe33))
|
||||
* **CommandInteraction:** ephemeral followup messages ([#5618](https://github.com/discordjs/discord.js/issues/5618)) ([68b40dd](https://github.com/discordjs/discord.js/commit/68b40dd91df70593c8271bd455fd0b3c6d19d334))
|
||||
* **CommandInteraction:** make options a collection ([#5705](https://github.com/discordjs/discord.js/issues/5705)) ([fdad140](https://github.com/discordjs/discord.js/commit/fdad14099779e61cb84dcd1cb2497e0e853a6144))
|
||||
* **Guild:** add the new nsfw_level property ([#5660](https://github.com/discordjs/discord.js/issues/5660)) ([3fe7add](https://github.com/discordjs/discord.js/commit/3fe7add2c5c07023d3cc83c06bba846c1328e446))
|
||||
* **GuildChannel:** createInvite target options ([#5514](https://github.com/discordjs/discord.js/issues/5514)) ([f831872](https://github.com/discordjs/discord.js/commit/f831872125214e39c8866ce1cf7c63159a3dba39))
|
||||
* **GuildChannel:** make createOverwrite and updateOverwrite not dependent on cache ([#5489](https://github.com/discordjs/discord.js/issues/5489)) ([58763b0](https://github.com/discordjs/discord.js/commit/58763b0e91b78d068121521ea3e853627b3ea325))
|
||||
* **GuildChannel#clone:** support for position property ([#5236](https://github.com/discordjs/discord.js/issues/5236)) ([d455cb6](https://github.com/discordjs/discord.js/commit/d455cb65a6188e7d7b6720848b5ce37dbf8b5dff))
|
||||
* **GuildMemberManager:** extend API coverage ([#4872](https://github.com/discordjs/discord.js/issues/4872)) ([2e2464b](https://github.com/discordjs/discord.js/commit/2e2464bf07c2b2e08d396b093126f887d19aec57))
|
||||
* **Message:** add ReplyMessageOptions for #reply ([#5296](https://github.com/discordjs/discord.js/issues/5296)) ([7ce741d](https://github.com/discordjs/discord.js/commit/7ce741dacd06fd8af0ab501e38be08cf6b506a62))
|
||||
* **Message:** allow editing files into messages ([#5718](https://github.com/discordjs/discord.js/issues/5718)) ([b212b64](https://github.com/discordjs/discord.js/commit/b212b64214ecee4f6118e78f9b90f3d3da574ecc))
|
||||
* **Rest:** show the data that is sent to Discord when an errors occurs ([#5701](https://github.com/discordjs/discord.js/issues/5701)) ([ef92339](https://github.com/discordjs/discord.js/commit/ef92339d073f82cdaa2bc69f7be8443ec16789a7))
|
||||
* add support for fetching multiple guilds ([#5472](https://github.com/discordjs/discord.js/issues/5472)) ([48d6850](https://github.com/discordjs/discord.js/commit/48d6850d9a8c34f407a22b6b401f2ed74415acd0))
|
||||
* easier guards for channelUpdate ([#5716](https://github.com/discordjs/discord.js/issues/5716)) ([d52bcd4](https://github.com/discordjs/discord.js/commit/d52bcd46ec5985f9f18da37ba9d7d77209f58337))
|
||||
* general component improvements ([#5787](https://github.com/discordjs/discord.js/issues/5787)) ([c4f1c75](https://github.com/discordjs/discord.js/commit/c4f1c75efa1cff1f9c775a266dccbe581305e79d))
|
||||
* GuildBanManager ([#5276](https://github.com/discordjs/discord.js/issues/5276)) ([6d09160](https://github.com/discordjs/discord.js/commit/6d09160f5ba878fcd1f8bae88b5e6347e632cd2c))
|
||||
* InteractionDeferOptions ([#5641](https://github.com/discordjs/discord.js/issues/5641)) ([ed593c9](https://github.com/discordjs/discord.js/commit/ed593c91fb7b87ae8b512c6f127e12f33c9631b6))
|
||||
* **Guild:** allow description and features in edit ([#5505](https://github.com/discordjs/discord.js/issues/5505)) ([8a059cc](https://github.com/discordjs/discord.js/commit/8a059cccb8ecbd0bf60d2ed395a8de0806b3395a))
|
||||
* **Guild:** nsfw guilds ([#5525](https://github.com/discordjs/discord.js/issues/5525)) ([5968323](https://github.com/discordjs/discord.js/commit/596832371cefef7739e8d714248d1c6d438eb8df))
|
||||
* **Guild:** replace `owner` with `fetchOwner` ([#5480](https://github.com/discordjs/discord.js/issues/5480)) ([1be67b8](https://github.com/discordjs/discord.js/commit/1be67b88516b104073e46574a180498bad2aa02b))
|
||||
* **Guild:** setChannelPositions parent, lockPermissions keys ([#5507](https://github.com/discordjs/discord.js/issues/5507)) ([4866e26](https://github.com/discordjs/discord.js/commit/4866e2672f28bfc481cf03533f7ba259050c80f4))
|
||||
* **GuildFeatures:** added the new screening features ([#5328](https://github.com/discordjs/discord.js/issues/5328)) ([3c175cb](https://github.com/discordjs/discord.js/commit/3c175cb5116fe50ba3084163565dd244a25b657f))
|
||||
* **GuildManager:** allow system channel flags in create ([#5504](https://github.com/discordjs/discord.js/issues/5504)) ([d9fa180](https://github.com/discordjs/discord.js/commit/d9fa180cf93f1a339192ae95dfb512482bd0ed0b))
|
||||
* **Message:** allow removing attachments ([#5557](https://github.com/discordjs/discord.js/issues/5557)) ([ca9e5a0](https://github.com/discordjs/discord.js/commit/ca9e5a0ee1afca544192df1daef744d5a35f1727))
|
||||
* **Message:** replace referencedMessage with fetchReference ([#5577](https://github.com/discordjs/discord.js/issues/5577)) ([1398431](https://github.com/discordjs/discord.js/commit/1398431bca9a3743758295f1effa2e7f6c35093e))
|
||||
* **MessageEmbed:** remove normalizeField validation ([#5459](https://github.com/discordjs/discord.js/issues/5459)) ([ff2f737](https://github.com/discordjs/discord.js/commit/ff2f7372f23f901620d3afff215f33be487521d5))
|
||||
* **MessageManager:** extend API coverage ([#4869](https://github.com/discordjs/discord.js/issues/4869)) ([c56c4a8](https://github.com/discordjs/discord.js/commit/c56c4a8dc86b0f37dd7c9ee9a4d422a52070b50c))
|
||||
* **ShardingManager:** add options typings ([#5583](https://github.com/discordjs/discord.js/issues/5583)) ([31b4390](https://github.com/discordjs/discord.js/commit/31b4390042e6557f7f9d2f258c79ea50ba4929e2))
|
||||
* add support for application command events ([#5596](https://github.com/discordjs/discord.js/issues/5596)) ([9f74f95](https://github.com/discordjs/discord.js/commit/9f74f95f69f4aa8a9a23c160e25dc61010c0a8e0))
|
||||
* interactions ([#5448](https://github.com/discordjs/discord.js/issues/5448)) ([f7643f7](https://github.com/discordjs/discord.js/commit/f7643f7bbe64003ad8b221006190dd15529651e9))
|
||||
* **Activity:** add missing fields ([#4984](https://github.com/discordjs/discord.js/issues/4984)) ([63ff6a0](https://github.com/discordjs/discord.js/commit/63ff6a07ebcba7e9134e3902e338e8dc6564ee63))
|
||||
* **APIMessage:** remove disableMentions ([#4836](https://github.com/discordjs/discord.js/issues/4836)) ([4107899](https://github.com/discordjs/discord.js/commit/41078997aefce2a9e683b9805aad6436612a3aa7))
|
||||
* **Application:** application flags ([#5147](https://github.com/discordjs/discord.js/issues/5147)) ([06e9d86](https://github.com/discordjs/discord.js/commit/06e9d86cb3dd11708c9cdd81f15970979e5b090d))
|
||||
* **BitField:** move problematic bit into the error message ([#5228](https://github.com/discordjs/discord.js/issues/5228)) ([273e955](https://github.com/discordjs/discord.js/commit/273e9557be68eb1c2466f29e1c41e9b146a777c1))
|
||||
* **Client:** add InviteGenerationOptions#additionalScopes ([#5215](https://github.com/discordjs/discord.js/issues/5215)) ([ae3c3d8](https://github.com/discordjs/discord.js/commit/ae3c3d80ee603fc46a28140107cb90c81da0afc9))
|
||||
* **ClientEvents:** add tuple labels to event arguments ([#5225](https://github.com/discordjs/discord.js/issues/5225)) ([764966e](https://github.com/discordjs/discord.js/commit/764966e398e693a5ec868bc22d722f8518656b3a))
|
||||
* **GuildChannel:** support conversion between text and news ([#5022](https://github.com/discordjs/discord.js/issues/5022)) ([5ac3b57](https://github.com/discordjs/discord.js/commit/5ac3b57f9bd53d1c20549a70942b023826f6f726))
|
||||
* **GuildEmojiManager:** implement GuildEmojiManager#fetch ([#4933](https://github.com/discordjs/discord.js/issues/4933)) ([ffe3140](https://github.com/discordjs/discord.js/commit/ffe31405ff559202be55473db7e8b34894fbf4a7))
|
||||
* **GuildMember:** #pending ([#5121](https://github.com/discordjs/discord.js/issues/5121)) ([c4c8171](https://github.com/discordjs/discord.js/commit/c4c817116f868cedb4ec20bcbf90b9b3d382621e))
|
||||
* **GuildMember:** make GuildMember#setNickname first param nullable ([#5070](https://github.com/discordjs/discord.js/issues/5070)) ([d70127c](https://github.com/discordjs/discord.js/commit/d70127cee69e66e87702a6db4b58ad12aa85f96c))
|
||||
* **GuildMemberManager:** add 'search' method ([#4154](https://github.com/discordjs/discord.js/issues/4154)) ([0ba2bcb](https://github.com/discordjs/discord.js/commit/0ba2bcb54582b38ee8eec8d1547b979bf1b7c755))
|
||||
* **GuildMemberManager:** throw TypeError on incorrect GuildMemberManager#ban params ([#4816](https://github.com/discordjs/discord.js/issues/4816)) ([863734a](https://github.com/discordjs/discord.js/commit/863734aba46c5e0d04fbc83d2ed314726bddcbc2))
|
||||
* **Message:** added string type for message nonce ([#4782](https://github.com/discordjs/discord.js/issues/4782)) ([4b555fd](https://github.com/discordjs/discord.js/commit/4b555fdf4c3b35fa0ea284f9cd56765ecb608b89))
|
||||
* **MessageAttachment:** support for #contentType ([#5481](https://github.com/discordjs/discord.js/issues/5481)) ([7b161f9](https://github.com/discordjs/discord.js/commit/7b161f93a040a6bdce6e7e26d7a3c3b6c61a04fd))
|
||||
* **SysChanFlags:** new flag and rename in sync with client ([#5506](https://github.com/discordjs/discord.js/issues/5506)) ([fe93a7e](https://github.com/discordjs/discord.js/commit/fe93a7e084189b54b8af82461809dee1da112b75))
|
||||
* move internal regular expressions to static properties ([#5384](https://github.com/discordjs/discord.js/issues/5384)) ([207735c](https://github.com/discordjs/discord.js/commit/207735cedcf9a998571a328c7c7b2414d3ebe9d5))
|
||||
* **Message|TextChannel:** Inline replies ([#4874](https://github.com/discordjs/discord.js/issues/4874)) ([60e5a0e](https://github.com/discordjs/discord.js/commit/60e5a0e46f57cf297b66f1a940d24a20f46b5319))
|
||||
* **ReactionCollector:** event create ([#4108](https://github.com/discordjs/discord.js/issues/4108)) ([09d1f2f](https://github.com/discordjs/discord.js/commit/09d1f2f18f5ec536bb25156553986fee51c80d1e)), closes [#2844](https://github.com/discordjs/discord.js/issues/2844)
|
||||
* **Rest:** better handling of global rate limit and invalid request tracking ([#4711](https://github.com/discordjs/discord.js/issues/4711)) ([9d2d606](https://github.com/discordjs/discord.js/commit/9d2d60691eb4bde729f40fb633ae257cf5bc6545))
|
||||
* **typings:** add ShardingManager.shardList to type definitions ([#5446](https://github.com/discordjs/discord.js/issues/5446)) ([32b0d71](https://github.com/discordjs/discord.js/commit/32b0d71af7e3afc401898753b1e8cb1e991b70e7))
|
||||
* **typings:** explicitly type PremiumTier and Collectors ([#5458](https://github.com/discordjs/discord.js/issues/5458)) ([7c49612](https://github.com/discordjs/discord.js/commit/7c49612d4bedfe13f7ed676c125cc7f7f33596df))
|
||||
* jsdelivr default file support ([#5424](https://github.com/discordjs/discord.js/issues/5424)) ([f469402](https://github.com/discordjs/discord.js/commit/f46940228e9f82db4af09ae2f2dad684db0d74ed))
|
||||
* make changes to PresenceData typings and docs ([#5317](https://github.com/discordjs/discord.js/issues/5317)) ([eb43ce4](https://github.com/discordjs/discord.js/commit/eb43ce4d4fb4d634696c5b0f026174dc0e435fe3))
|
||||
* promisified single interaction collection ([#5770](https://github.com/discordjs/discord.js/issues/5770)) ([c2b3ed0](https://github.com/discordjs/discord.js/commit/c2b3ed09a0ec7f9b7453d0bcf9f2900e408f5001))
|
||||
* **MessageTypes:** add 16 and 17 ([#4685](https://github.com/discordjs/discord.js/issues/4685)) ([c9107e3](https://github.com/discordjs/discord.js/commit/c9107e35fa8b74f8ad7a7d3ee7d7178a35790e18))
|
||||
* stage channels ([#5456](https://github.com/discordjs/discord.js/issues/5456)) ([eec7cf7](https://github.com/discordjs/discord.js/commit/eec7cf7634653fc02ee4f94e970960174a0e6d1b))
|
||||
* stage instances ([#5749](https://github.com/discordjs/discord.js/issues/5749)) ([918921e](https://github.com/discordjs/discord.js/commit/918921e8211fc16e9b12d2502f3168264246ea22))
|
||||
* **Browser:** remove browser <20> ([#5113](https://github.com/discordjs/discord.js/issues/5113)) ([0a591a9](https://github.com/discordjs/discord.js/commit/0a591a96974ab8b2aef7d7b9b64ec63d0fbe4ec4))
|
||||
* **Role:** role tags ([#4628](https://github.com/discordjs/discord.js/issues/4628)) ([d6234b7](https://github.com/discordjs/discord.js/commit/d6234b764ecbf12ebc0a795429a6aa3a650f5a6c))
|
||||
* **ShardingManager:** Allow b-Eval/fetchClientValues on a specific shard when not all are ready ([#5222](https://github.com/discordjs/discord.js/issues/5222)) ([001676c](https://github.com/discordjs/discord.js/commit/001676c7a97f4e44c6601dd84aa0354ea94b7c25))
|
||||
* **Sticker:** added Sticker ([#4909](https://github.com/discordjs/discord.js/issues/4909)) ([026afc2](https://github.com/discordjs/discord.js/commit/026afc2c1a88bc210c973bcf235fef3484571111))
|
||||
* **Util:** allow array for StringOptions' char ([#5566](https://github.com/discordjs/discord.js/issues/5566)) ([fbcbb29](https://github.com/discordjs/discord.js/commit/fbcbb29884a35308a7af2169f5f9ae5658c458e8))
|
||||
* **Util:** make `cleanContent` take a channel instead of a message ([#5535](https://github.com/discordjs/discord.js/issues/5535)) ([f1c0c04](https://github.com/discordjs/discord.js/commit/f1c0c043b516f4158ab9d473419e3b5e125a4c03))
|
||||
* **Voice:** implement support for @discordjs/voice ([#5402](https://github.com/discordjs/discord.js/issues/5402)) ([7b2e12b](https://github.com/discordjs/discord.js/commit/7b2e12b102984abf61132e1057558ef7f04e6d83))
|
||||
* **Webhook:** add '(edit|delete)Message' methods ([#5223](https://github.com/discordjs/discord.js/issues/5223)) ([7cabc1c](https://github.com/discordjs/discord.js/commit/7cabc1c490ddd9518528e12a58a746d65e43d4eb))
|
||||
* **Webhook:** add 'fetchMessage' method ([#5530](https://github.com/discordjs/discord.js/issues/5530)) ([63398d6](https://github.com/discordjs/discord.js/commit/63398d6ae46f0487c4d5d8bfe823952a803e4a5a))
|
||||
* **Webhook:** sourceGuild, sourceChannel, improve owner ([#5508](https://github.com/discordjs/discord.js/issues/5508)) ([116ecf2](https://github.com/discordjs/discord.js/commit/116ecf246e89db4d629a13877a440260c7504e30))
|
||||
* **WebSocketManager:** let identify throw on depleted limits ([#5283](https://github.com/discordjs/discord.js/issues/5283)) ([624a446](https://github.com/discordjs/discord.js/commit/624a4464ca86bfa0b095ecb2cdaac2e8030cc413))
|
||||
* BaseGuildEmojiManager ([#4934](https://github.com/discordjs/discord.js/issues/4934)) ([8d650a7](https://github.com/discordjs/discord.js/commit/8d650a72509a3f369ae31ec421d1892d182175e4))
|
||||
|
||||
|
||||
### Reverts
|
||||
|
||||
* support for nested arrays of components, fix error handling ([#6081](https://github.com/discordjs/discord.js/issues/6081)) ([1dcad05](https://github.com/discordjs/discord.js/commit/1dcad051a835407bc24de3446dbd0ac3c0efeefc))
|
||||
* **BitField:** ⏪ Bring back-compatibility after BitField serialization ([#5910](https://github.com/discordjs/discord.js/issues/5910)) ([0a0630c](https://github.com/discordjs/discord.js/commit/0a0630c0498d8ae24e703a2bfdf978541deb9b60))
|
||||
* 5047 ([#5050](https://github.com/discordjs/discord.js/issues/5050)) ([b2a6720](https://github.com/discordjs/discord.js/commit/b2a672047745b0a47729ef775482e06a20b38db3))
|
||||
|
||||
|
||||
### BREAKING CHANGES
|
||||
|
||||
For breaking changes please reference: <https://discordjs.guide/additional-info/changes-in-v13.html>
|
||||
2
LICENSE
2
LICENSE
@@ -175,7 +175,7 @@
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Copyright 2015 - 2020 Amish Shah
|
||||
Copyright 2015 - 2021 Amish Shah
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
105
README.md
105
README.md
@@ -5,34 +5,18 @@
|
||||
</p>
|
||||
<br />
|
||||
<p>
|
||||
<a href="https://discord.gg/bRCvFy9"><img src="https://discordapp.com/api/guilds/222078108977594368/embed.png" alt="Discord server" /></a>
|
||||
<a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a>
|
||||
<a href="https://www.npmjs.com/package/discord.js"><img src="https://img.shields.io/npm/v/discord.js.svg?maxAge=3600" alt="NPM version" /></a>
|
||||
<a href="https://www.npmjs.com/package/discord.js"><img src="https://img.shields.io/npm/dt/discord.js.svg?maxAge=3600" alt="NPM downloads" /></a>
|
||||
<a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/workflows/Testing/badge.svg" alt="Build status" /></a>
|
||||
<a href="https://david-dm.org/discordjs/discord.js"><img src="https://img.shields.io/david/discordjs/discord.js.svg?maxAge=3600" alt="Dependencies" /></a>
|
||||
<a href="https://www.patreon.com/discordjs"><img src="https://img.shields.io/badge/donate-patreon-F96854.svg" alt="Patreon" /></a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://nodei.co/npm/discord.js/"><img src="https://nodei.co/npm/discord.js.png?downloads=true&stars=true" alt="npm installnfo" /></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
## Table of contents
|
||||
|
||||
- [About](#about)
|
||||
- [Installation](#installation)
|
||||
- [Audio engines](#audio-engines)
|
||||
- [Optional packages](#optional-packages)
|
||||
- [Example Usage](#example-usage)
|
||||
- [Links](#links)
|
||||
- [Extensions](#extensions)
|
||||
- [Contributing](#contributing)
|
||||
- [Help](#help)
|
||||
|
||||
## About
|
||||
|
||||
discord.js is a powerful [Node.js](https://nodejs.org) module that allows you to easily interact with the
|
||||
[Discord API](https://discordapp.com/developers/docs/intro).
|
||||
[Discord API](https://discord.com/developers/docs/intro).
|
||||
|
||||
- Object-oriented
|
||||
- Predictable abstractions
|
||||
@@ -41,42 +25,73 @@ discord.js is a powerful [Node.js](https://nodejs.org) module that allows you to
|
||||
|
||||
## Installation
|
||||
|
||||
**Node.js 12.0.0 or newer is required.**
|
||||
Ignore any warnings about unmet peer dependencies, as they're all optional.
|
||||
**Node.js 16.6.0 or newer is required.**
|
||||
|
||||
Without voice support: `npm install discord.js`
|
||||
With voice support ([@discordjs/opus](https://www.npmjs.com/package/@discordjs/opus)): `npm install discord.js @discordjs/opus`
|
||||
With voice support ([opusscript](https://www.npmjs.com/package/opusscript)): `npm install discord.js opusscript`
|
||||
|
||||
### Audio engines
|
||||
|
||||
The preferred audio engine is @discordjs/opus, as it performs significantly better than opusscript. When both are available, discord.js will automatically choose @discordjs/opus.
|
||||
Using opusscript is only recommended for development environments where @discordjs/opus is tough to get working.
|
||||
For production bots, using @discordjs/opus should be considered a necessity, especially if they're going to be running on multiple servers.
|
||||
```sh-session
|
||||
npm install discord.js
|
||||
yarn add discord.js
|
||||
pnpm add discord.js
|
||||
```
|
||||
|
||||
### Optional packages
|
||||
|
||||
- [zlib-sync](https://www.npmjs.com/package/zlib-sync) for WebSocket data compression and inflation (`npm install zlib-sync`)
|
||||
- [erlpack](https://github.com/discordapp/erlpack) for significantly faster WebSocket data (de)serialisation (`npm install discordapp/erlpack`)
|
||||
- One of the following packages can be installed for faster voice packet encryption and decryption:
|
||||
- [sodium](https://www.npmjs.com/package/sodium) (`npm install sodium`)
|
||||
- [libsodium.js](https://www.npmjs.com/package/libsodium-wrappers) (`npm install libsodium-wrappers`)
|
||||
- [erlpack](https://github.com/discord/erlpack) for significantly faster WebSocket data (de)serialisation (`npm install discord/erlpack`)
|
||||
- [bufferutil](https://www.npmjs.com/package/bufferutil) for a much faster WebSocket connection (`npm install bufferutil`)
|
||||
- [utf-8-validate](https://www.npmjs.com/package/utf-8-validate) in combination with `bufferutil` for much faster WebSocket processing (`npm install utf-8-validate`)
|
||||
- [@discordjs/voice](https://github.com/discordjs/voice) for interacting with the Discord Voice API
|
||||
|
||||
## Example usage
|
||||
|
||||
Install all required dependencies:
|
||||
```sh-session
|
||||
npm install discord.js @discordjs/rest discord-api-types
|
||||
yarn add discord.js @discordjs/rest discord-api-types
|
||||
pnpm add discord.js @discordjs/rest discord-api-types
|
||||
```
|
||||
|
||||
Register a slash command against the Discord API:
|
||||
```js
|
||||
const Discord = require('discord.js');
|
||||
const client = new Discord.Client();
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v9');
|
||||
|
||||
const commands = [{
|
||||
name: 'ping',
|
||||
description: 'Replies with Pong!'
|
||||
}];
|
||||
|
||||
const rest = new REST({ version: '9' }).setToken('token');
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID),
|
||||
{ body: commands },
|
||||
);
|
||||
|
||||
console.log('Successfully reloaded application (/) commands.');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
})();
|
||||
```
|
||||
|
||||
Afterwards we can create a quite simple example bot:
|
||||
```js
|
||||
const { Client, Intents } = require('discord.js');
|
||||
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
|
||||
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
});
|
||||
|
||||
client.on('message', msg => {
|
||||
if (msg.content === 'ping') {
|
||||
msg.reply('pong');
|
||||
client.on('interactionCreate', async interaction => {
|
||||
if (!interaction.isCommand()) return;
|
||||
|
||||
if (interaction.commandName === 'ping') {
|
||||
await interaction.reply('Pong!');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -86,14 +101,14 @@ client.login('token');
|
||||
## Links
|
||||
|
||||
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/website))
|
||||
- [Documentation](https://discord.js.org/#/docs/main/master/general/welcome)
|
||||
- [Guide](https://discordjs.guide/) ([source](https://github.com/discordjs/guide)) - this is still for stable
|
||||
See also the [Update Guide](https://discordjs.guide/additional-info/changes-in-v12.html), including updated and removed items in the library.
|
||||
- [Discord.js Discord server](https://discord.gg/bRCvFy9)
|
||||
- [Documentation](https://discord.js.org/#/docs)
|
||||
- [Guide](https://discordjs.guide/) ([source](https://github.com/discordjs/guide))
|
||||
See also the [Update Guide](https://discordjs.guide/additional-info/changes-in-v13.html), including updated and removed items in the library.
|
||||
- [Discord.js Discord server](https://discord.gg/djs)
|
||||
- [Discord API Discord server](https://discord.gg/discord-api)
|
||||
- [GitHub](https://github.com/discordjs/discord.js)
|
||||
- [NPM](https://www.npmjs.com/package/discord.js)
|
||||
- [Related libraries](https://discordapi.com/unofficial/libs.html)
|
||||
- [Related libraries](https://discord.com/developers/docs/topics/community-resources#libraries)
|
||||
|
||||
### Extensions
|
||||
|
||||
@@ -103,9 +118,9 @@ client.login('token');
|
||||
|
||||
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
|
||||
[documentation](https://discord.js.org/#/docs).
|
||||
See [the contribution guide](https://github.com/discordjs/discord.js/blob/master/.github/CONTRIBUTING.md) if you'd like to submit a PR.
|
||||
See [the contribution guide](https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md) if you'd like to submit a PR.
|
||||
|
||||
## Help
|
||||
|
||||
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle
|
||||
nudge in the right direction, please don't hesitate to join our official [Discord.js Server](https://discord.gg/bRCvFy9).
|
||||
nudge in the right direction, please don't hesitate to join our official [Discord.js Server](https://discord.gg/djs).
|
||||
|
||||
@@ -1,163 +0,0 @@
|
||||
# Sending Attachments
|
||||
|
||||
In here you'll see a few examples showing how you can send an attachment using discord.js.
|
||||
|
||||
## Sending an attachment using a URL
|
||||
|
||||
There are a few ways you can do this, but we'll show you the easiest.
|
||||
|
||||
The following examples use [MessageAttachment](/#/docs/main/master/class/MessageAttachment).
|
||||
|
||||
```js
|
||||
// Extract the required classes from the discord.js module
|
||||
const { Client, MessageAttachment } = require('discord.js');
|
||||
|
||||
// Create an instance of a Discord client
|
||||
const client = new Client();
|
||||
|
||||
/**
|
||||
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
|
||||
* received from Discord
|
||||
*/
|
||||
client.on('ready', () => {
|
||||
console.log('I am ready!');
|
||||
});
|
||||
|
||||
client.on('message', message => {
|
||||
// If the message is '!rip'
|
||||
if (message.content === '!rip') {
|
||||
// Create the attachment using MessageAttachment
|
||||
const attachment = new MessageAttachment('https://i.imgur.com/w3duR07.png');
|
||||
// Send the attachment in the message channel
|
||||
message.channel.send(attachment);
|
||||
}
|
||||
});
|
||||
|
||||
// Log our bot in using the token from https://discordapp.com/developers/applications/me
|
||||
client.login('your token here');
|
||||
```
|
||||
|
||||
And here is the result:
|
||||
|
||||

|
||||
|
||||
But what if you want to send an attachment with a message content? Fear not, for it is easy to do that too! We'll recommend reading [the TextChannel's "send" function documentation](/#/docs/main/master/class/TextChannel?scrollTo=send) to see what other options are available.
|
||||
|
||||
```js
|
||||
// Extract the required classes from the discord.js module
|
||||
const { Client, MessageAttachment } = require('discord.js');
|
||||
|
||||
// Create an instance of a Discord client
|
||||
const client = new Client();
|
||||
|
||||
/**
|
||||
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
|
||||
* received from Discord
|
||||
*/
|
||||
client.on('ready', () => {
|
||||
console.log('I am ready!');
|
||||
});
|
||||
|
||||
client.on('message', message => {
|
||||
// If the message is '!rip'
|
||||
if (message.content === '!rip') {
|
||||
// Create the attachment using MessageAttachment
|
||||
const attachment = new MessageAttachment('https://i.imgur.com/w3duR07.png');
|
||||
// Send the attachment in the message channel with a content
|
||||
message.channel.send(`${message.author},`, attachment);
|
||||
}
|
||||
});
|
||||
|
||||
// Log our bot in using the token from https://discordapp.com/developers/applications/me
|
||||
client.login('your token here');
|
||||
```
|
||||
|
||||
And here's the result of this one:
|
||||
|
||||

|
||||
|
||||
## Sending a local file or buffer
|
||||
|
||||
Sending a local file isn't hard either! We'll be using [MessageAttachment](/#/docs/main/master/class/MessageAttachment) for these examples too.
|
||||
|
||||
```js
|
||||
// Extract the required classes from the discord.js module
|
||||
const { Client, MessageAttachment } = require('discord.js');
|
||||
|
||||
// Create an instance of a Discord client
|
||||
const client = new Client();
|
||||
|
||||
/**
|
||||
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
|
||||
* received from Discord
|
||||
*/
|
||||
client.on('ready', () => {
|
||||
console.log('I am ready!');
|
||||
});
|
||||
|
||||
client.on('message', message => {
|
||||
// If the message is '!rip'
|
||||
if (message.content === '!rip') {
|
||||
// Create the attachment using MessageAttachment
|
||||
const attachment = new MessageAttachment('./rip.png');
|
||||
// Send the attachment in the message channel with a content
|
||||
message.channel.send(`${message.author},`, attachment);
|
||||
}
|
||||
});
|
||||
|
||||
// Log our bot in using the token from https://discordapp.com/developers/applications/me
|
||||
client.login('your token here');
|
||||
```
|
||||
|
||||
The results are the same as the URL examples:
|
||||
|
||||

|
||||
|
||||
But what if you have a buffer from an image? Or a text document? Well, it's the same as sending a local file or a URL!
|
||||
|
||||
In the following example, we'll be getting the buffer from a `memes.txt` file, and send it in the message channel.
|
||||
You can use any buffer you want, and send it. Just make sure to overwrite the filename if it isn't an image!
|
||||
|
||||
```js
|
||||
// Extract the required classes from the discord.js module
|
||||
const { Client, MessageAttachment } = require('discord.js');
|
||||
|
||||
// Import the native fs module
|
||||
const fs = require('fs');
|
||||
|
||||
// Create an instance of a Discord client
|
||||
const client = new Client();
|
||||
|
||||
/**
|
||||
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
|
||||
* received from Discord
|
||||
*/
|
||||
client.on('ready', () => {
|
||||
console.log('I am ready!');
|
||||
});
|
||||
|
||||
client.on('message', message => {
|
||||
// If the message is '!memes'
|
||||
if (message.content === '!memes') {
|
||||
// Get the buffer from the 'memes.txt', assuming that the file exists
|
||||
const buffer = fs.readFileSync('./memes.txt');
|
||||
|
||||
/**
|
||||
* Create the attachment using MessageAttachment,
|
||||
* overwritting the default file name to 'memes.txt'
|
||||
* Read more about it over at
|
||||
* http://discord.js.org/#/docs/main/master/class/MessageAttachment
|
||||
*/
|
||||
const attachment = new MessageAttachment(buffer, 'memes.txt');
|
||||
// Send the attachment in the message channel with a content
|
||||
message.channel.send(`${message.author}, here are your memes!`, attachment);
|
||||
}
|
||||
});
|
||||
|
||||
// Log our bot in using the token from https://discordapp.com/developers/applications/me
|
||||
client.login('your token here');
|
||||
```
|
||||
|
||||
And of course, the results are:
|
||||
|
||||

|
||||
@@ -1,31 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Send a user a link to their avatar
|
||||
*/
|
||||
|
||||
// Import the discord.js module
|
||||
const Discord = require('discord.js');
|
||||
|
||||
// Create an instance of a Discord client
|
||||
const client = new Discord.Client();
|
||||
|
||||
/**
|
||||
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
|
||||
* received from Discord
|
||||
*/
|
||||
client.on('ready', () => {
|
||||
console.log('I am ready!');
|
||||
});
|
||||
|
||||
// Create an event listener for messages
|
||||
client.on('message', message => {
|
||||
// If the message is "what is my avatar"
|
||||
if (message.content === 'what is my avatar') {
|
||||
// Send the user's avatar URL
|
||||
message.reply(message.author.displayAvatarURL());
|
||||
}
|
||||
});
|
||||
|
||||
// Log our bot in using the token from https://discordapp.com/developers/applications/me
|
||||
client.login('your token here');
|
||||
@@ -1,40 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* An example of how you can send embeds
|
||||
*/
|
||||
|
||||
// Extract the required classes from the discord.js module
|
||||
const { Client, MessageEmbed } = require('discord.js');
|
||||
|
||||
// Create an instance of a Discord client
|
||||
const client = new Client();
|
||||
|
||||
/**
|
||||
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
|
||||
* received from Discord
|
||||
*/
|
||||
client.on('ready', () => {
|
||||
console.log('I am ready!');
|
||||
});
|
||||
|
||||
client.on('message', message => {
|
||||
// If the message is "how to embed"
|
||||
if (message.content === 'how to embed') {
|
||||
// We can create embeds using the MessageEmbed constructor
|
||||
// Read more about all that you can do with the constructor
|
||||
// over at https://discord.js.org/#/docs/main/master/class/MessageEmbed
|
||||
const embed = new MessageEmbed()
|
||||
// Set the title of the field
|
||||
.setTitle('A slick little embed')
|
||||
// Set the color of the embed
|
||||
.setColor(0xff0000)
|
||||
// Set the main content of the embed
|
||||
.setDescription('Hello, this is a slick embed!');
|
||||
// Send the embed to the same channel as the message
|
||||
message.channel.send(embed);
|
||||
}
|
||||
});
|
||||
|
||||
// Log our bot in using the token from https://discordapp.com/developers/applications/me
|
||||
client.login('your token here');
|
||||
@@ -1,32 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* A bot that welcomes new guild members when they join
|
||||
*/
|
||||
|
||||
// Import the discord.js module
|
||||
const Discord = require('discord.js');
|
||||
|
||||
// Create an instance of a Discord client
|
||||
const client = new Discord.Client();
|
||||
|
||||
/**
|
||||
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
|
||||
* received from Discord
|
||||
*/
|
||||
client.on('ready', () => {
|
||||
console.log('I am ready!');
|
||||
});
|
||||
|
||||
// Create an event listener for new guild members
|
||||
client.on('guildMemberAdd', member => {
|
||||
// Send the message to a designated channel on a server:
|
||||
const channel = member.guild.channels.cache.find(ch => ch.name === 'member-log');
|
||||
// Do nothing if the channel wasn't found on this server
|
||||
if (!channel) return;
|
||||
// Send the message, mentioning the member
|
||||
channel.send(`Welcome to the server, ${member}`);
|
||||
});
|
||||
|
||||
// Log our bot in using the token from https://discordapp.com/developers/applications/me
|
||||
client.login('your token here');
|
||||
@@ -1,151 +0,0 @@
|
||||
# Moderation
|
||||
|
||||
In here, you'll see some basic examples for kicking and banning a member.
|
||||
|
||||
## Kicking a member
|
||||
|
||||
Let's say you have a member that you'd like to kick. Here is an example of how you _can_ do it.
|
||||
|
||||
```js
|
||||
// Import the discord.js module
|
||||
const Discord = require('discord.js');
|
||||
|
||||
// Create an instance of a Discord client
|
||||
const client = new Discord.Client();
|
||||
|
||||
/**
|
||||
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
|
||||
* received from Discord
|
||||
*/
|
||||
client.on('ready', () => {
|
||||
console.log('I am ready!');
|
||||
});
|
||||
|
||||
client.on('message', message => {
|
||||
// Ignore messages that aren't from a guild
|
||||
if (!message.guild) return;
|
||||
|
||||
// If the message content starts with "!kick"
|
||||
if (message.content.startsWith('!kick')) {
|
||||
// Assuming we mention someone in the message, this will return the user
|
||||
// Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
|
||||
const user = message.mentions.users.first();
|
||||
// If we have a user mentioned
|
||||
if (user) {
|
||||
// Now we get the member from the user
|
||||
const member = message.guild.member(user);
|
||||
// If the member is in the guild
|
||||
if (member) {
|
||||
/**
|
||||
* Kick the member
|
||||
* Make sure you run this on a member, not a user!
|
||||
* There are big differences between a user and a member
|
||||
*/
|
||||
member
|
||||
.kick('Optional reason that will display in the audit logs')
|
||||
.then(() => {
|
||||
// We let the message author know we were able to kick the person
|
||||
message.reply(`Successfully kicked ${user.tag}`);
|
||||
})
|
||||
.catch(err => {
|
||||
// An error happened
|
||||
// This is generally due to the bot not being able to kick the member,
|
||||
// either due to missing permissions or role hierarchy
|
||||
message.reply('I was unable to kick the member');
|
||||
// Log the error
|
||||
console.error(err);
|
||||
});
|
||||
} else {
|
||||
// The mentioned user isn't in this guild
|
||||
message.reply("That user isn't in this guild!");
|
||||
}
|
||||
// Otherwise, if no user was mentioned
|
||||
} else {
|
||||
message.reply("You didn't mention the user to kick!");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Log our bot in using the token from https://discordapp.com/developers/applications/me
|
||||
client.login('your token here');
|
||||
```
|
||||
|
||||
And the result is:
|
||||
|
||||

|
||||
|
||||
## Banning a member
|
||||
|
||||
Banning works the same way as kicking, but it has slightly more options that can be changed.
|
||||
|
||||
```js
|
||||
// Import the discord.js module
|
||||
const Discord = require('discord.js');
|
||||
|
||||
// Create an instance of a Discord client
|
||||
const client = new Discord.Client();
|
||||
|
||||
/**
|
||||
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
|
||||
* received from Discord
|
||||
*/
|
||||
client.on('ready', () => {
|
||||
console.log('I am ready!');
|
||||
});
|
||||
|
||||
client.on('message', message => {
|
||||
// Ignore messages that aren't from a guild
|
||||
if (!message.guild) return;
|
||||
|
||||
// if the message content starts with "!ban"
|
||||
if (message.content.startsWith('!ban')) {
|
||||
// Assuming we mention someone in the message, this will return the user
|
||||
// Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
|
||||
const user = message.mentions.users.first();
|
||||
// If we have a user mentioned
|
||||
if (user) {
|
||||
// Now we get the member from the user
|
||||
const member = message.guild.member(user);
|
||||
// If the member is in the guild
|
||||
if (member) {
|
||||
/**
|
||||
* Ban the member
|
||||
* Make sure you run this on a member, not a user!
|
||||
* There are big differences between a user and a member
|
||||
* Read more about what ban options there are over at
|
||||
* https://discord.js.org/#/docs/main/master/class/GuildMember?scrollTo=ban
|
||||
*/
|
||||
member
|
||||
.ban({
|
||||
reason: 'They were bad!',
|
||||
})
|
||||
.then(() => {
|
||||
// We let the message author know we were able to ban the person
|
||||
message.reply(`Successfully banned ${user.tag}`);
|
||||
})
|
||||
.catch(err => {
|
||||
// An error happened
|
||||
// This is generally due to the bot not being able to ban the member,
|
||||
// either due to missing permissions or role hierarchy
|
||||
message.reply('I was unable to ban the member');
|
||||
// Log the error
|
||||
console.error(err);
|
||||
});
|
||||
} else {
|
||||
// The mentioned user isn't in this guild
|
||||
message.reply("That user isn't in this guild!");
|
||||
}
|
||||
} else {
|
||||
// Otherwise, if no user was mentioned
|
||||
message.reply("You didn't mention the user to ban!");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Log our bot in using the token from https://discordapp.com/developers/applications/me
|
||||
client.login('your token here');
|
||||
```
|
||||
|
||||
And the result is:
|
||||
|
||||

|
||||
@@ -1,31 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* A ping pong bot, whenever you send "ping", it replies "pong".
|
||||
*/
|
||||
|
||||
// Import the discord.js module
|
||||
const Discord = require('discord.js');
|
||||
|
||||
// Create an instance of a Discord client
|
||||
const client = new Discord.Client();
|
||||
|
||||
/**
|
||||
* The ready event is vital, it means that only _after_ this will your bot start reacting to information
|
||||
* received from Discord
|
||||
*/
|
||||
client.on('ready', () => {
|
||||
console.log('I am ready!');
|
||||
});
|
||||
|
||||
// Create an event listener for messages
|
||||
client.on('message', message => {
|
||||
// If the message is "ping"
|
||||
if (message.content === 'ping') {
|
||||
// Send "pong" to the same channel
|
||||
message.channel.send('pong');
|
||||
}
|
||||
});
|
||||
|
||||
// Log our bot in using the token from https://discordapp.com/developers/applications/me
|
||||
client.login('your token here');
|
||||
@@ -1,14 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Send a message using a webhook
|
||||
*/
|
||||
|
||||
// Import the discord.js module
|
||||
const Discord = require('discord.js');
|
||||
|
||||
// Create a new webhook
|
||||
const hook = new Discord.WebhookClient('webhook id', 'webhook token');
|
||||
|
||||
// Send a message using the webhook
|
||||
hook.send('I am now alive!');
|
||||
@@ -1,30 +0,0 @@
|
||||
# Frequently Asked Questions
|
||||
|
||||
These questions are some of the most frequently asked.
|
||||
|
||||
## No matter what, I get `SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode`‽
|
||||
|
||||
Update to Node.js 12.0.0 or newer.
|
||||
|
||||
## How do I get voice working?
|
||||
|
||||
- Install FFMPEG.
|
||||
- Install either the `@discordjs/opus` package or the `opusscript` package.
|
||||
@discordjs/opus is greatly preferred, due to it having significantly better performance.
|
||||
|
||||
## How do I install FFMPEG?
|
||||
|
||||
- **npm:** `npm install ffmpeg-static`
|
||||
- **Ubuntu 16.04:** `sudo apt install ffmpeg`
|
||||
- **Ubuntu 14.04:** `sudo apt-get install libav-tools`
|
||||
- **Windows:** `npm install ffmpeg-static` or see the [FFMPEG section of AoDude's guide](https://github.com/bdistin/OhGodMusicBot/blob/master/README.md#download-ffmpeg).
|
||||
|
||||
## How do I set up @discordjs/opus?
|
||||
|
||||
- **Ubuntu:** Simply run `npm install @discordjs/opus`, and it's done. Congrats!
|
||||
- **Windows:** Run `npm install --global --production windows-build-tools` in an admin command prompt or PowerShell.
|
||||
Then, running `npm install @discordjs/opus` in your bot's directory should successfully build it. Woo!
|
||||
|
||||
Other questions can be found at the [official Discord.js guide](https://discordjs.guide/popular-topics/common-questions.html)
|
||||
If you have issues not listed here or on the guide, feel free to ask in the [official Discord.js server](https://discord.gg/bRCvFy9).
|
||||
Always make sure to read the [documentation](https://discord.js.org/#/docs/main/stable/general/welcome).
|
||||
@@ -1,195 +0,0 @@
|
||||
# Version 12.0.0
|
||||
|
||||
v12.0.0 contains many new and improved features, optimisations, and bug fixes.
|
||||
See [the changelog](https://github.com/discordjs/discord.js/releases/tag/12.0.0) for a full list of changes.
|
||||
You can also visit [the guide](https://discordjs.guide/additional-info/changes-in-v12.html) for help with updating your v11 code to v12.
|
||||
|
||||
# Version 11.1.0
|
||||
|
||||
v11.1.0 features improved voice and gateway stability, as well as support for new features such as audit logs and searching for messages.
|
||||
See [the changelog](https://github.com/discordjs/discord.js/releases/tag/11.1.0) for a full list of changes, including
|
||||
information about deprecations.
|
||||
|
||||
# Version 11
|
||||
|
||||
Version 11 contains loads of new and improved features, optimisations, and bug fixes.
|
||||
See [the changelog](https://github.com/discordjs/discord.js/releases/tag/11.0.0) for a full list of changes.
|
||||
|
||||
## Significant additions
|
||||
|
||||
- Message Reactions and Embeds (rich text)
|
||||
- Support for uws and erlpack for better performance
|
||||
- OAuthApplication support
|
||||
- Web distributions
|
||||
|
||||
## Breaking changes
|
||||
|
||||
### Client.login() no longer supports logging in with email + password
|
||||
|
||||
Logging in with an email and password has always been heavily discouraged since the advent of proper token support, but in v11 we have made the decision to completely remove the functionality, since Hammer & Chisel have [officially stated](https://github.com/hammerandchisel/discord-api-docs/issues/69#issuecomment-223886862) it simply shouldn't be done.
|
||||
|
||||
User accounts can still log in with tokens just like bot accounts. To obtain the token for a user account, you can log in to Discord with that account, and use Ctrl + Shift + I to open the developer tools. In the console tab, evaluating `localStorage.token` will give you the token for that account.
|
||||
|
||||
### ClientUser.setEmail()/setPassword() now require the current password, as well as setUsername() on user accounts
|
||||
|
||||
Since you can no longer log in with email and password, you must provide the current account password to the `setEmail()`, `setPassword()`, and `setUsername()` methods for user accounts (self-bots).
|
||||
|
||||
### Removed TextBasedChannel.sendTTSMessage()
|
||||
|
||||
This method was deemed to be an entirely pointless shortcut that virtually nobody even used.
|
||||
The same results can be achieved by passing options to `send()` or `sendMessage()`.
|
||||
|
||||
Example:
|
||||
|
||||
```js
|
||||
channel.send('Hi there', { tts: true });
|
||||
```
|
||||
|
||||
### Using Collection.find()/exists() with IDs will throw an error
|
||||
|
||||
This is simply to help prevent a common mistake that is made frequently.
|
||||
To find something or check its existence using an ID, you should use `.get()` and `.has()` which are part of the [ES6 Map class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map), which Collection is an extension of.
|
||||
|
||||
# Version 10
|
||||
|
||||
Version 10's non-BC changes focus on cleaning up some inconsistencies that exist in previous versions.
|
||||
Upgrading from v9 should be quick and painless.
|
||||
|
||||
## Client options
|
||||
|
||||
All client options have been converted to camelCase rather than snake_case, and `max_message_cache` was renamed to `messageCacheMaxSize`.
|
||||
|
||||
v9 code example:
|
||||
|
||||
```js
|
||||
const client = new Discord.Client({
|
||||
disable_everyone: true,
|
||||
max_message_cache: 500,
|
||||
message_cache_lifetime: 120,
|
||||
message_sweep_interval: 60,
|
||||
});
|
||||
```
|
||||
|
||||
v10 code example:
|
||||
|
||||
```js
|
||||
const client = new Discord.Client({
|
||||
disableEveryone: true,
|
||||
messageCacheMaxSize: 500,
|
||||
messageCacheLifetime: 120,
|
||||
messageSweepInterval: 60,
|
||||
});
|
||||
```
|
||||
|
||||
## Presences
|
||||
|
||||
Presences have been completely restructured.
|
||||
Previous versions of discord.js assumed that users had the same presence amongst all guilds - with the introduction of sharding, however, this is no longer the case.
|
||||
|
||||
v9 discord.js code may look something like this:
|
||||
|
||||
```js
|
||||
User.status; // the status of the user
|
||||
User.game; // the game that the user is playing
|
||||
ClientUser.setStatus(status, game, url); // set the new status for the user
|
||||
```
|
||||
|
||||
v10 moves presences to GuildMember instances. For the sake of simplicity, though, User classes also expose presences.
|
||||
When accessing a presence on a User object, it simply finds the first GuildMember for the user, and uses its presence.
|
||||
Additionally, the introduction of the Presence class keeps all of the presence data organised.
|
||||
|
||||
**It is strongly recommended that you use a GuildMember's presence where available, rather than a User.
|
||||
A user may have an entirely different presence between two different guilds.**
|
||||
|
||||
v10 code:
|
||||
|
||||
```js
|
||||
MemberOrUser.presence.status; // the status of the member or user
|
||||
MemberOrUser.presence.game; // the game that the member or user is playing
|
||||
ClientUser.setStatus(status); // online, idle, dnd, offline
|
||||
ClientUser.setGame(game, streamingURL); // a game
|
||||
ClientUser.setPresence(fullPresence); // status and game combined
|
||||
```
|
||||
|
||||
## Voice
|
||||
|
||||
Voice has been rewritten internally, but in a backwards-compatible manner.
|
||||
There is only one breaking change here; the `disconnected` event was renamed to `disconnect`.
|
||||
Several more events have been made available to a VoiceConnection, so see the documentation.
|
||||
|
||||
## Events
|
||||
|
||||
Many events have been renamed or had their arguments change.
|
||||
|
||||
### Client events
|
||||
|
||||
| Version 9 | Version 10 |
|
||||
| ---------------------------------------------- | --------------------------------------- |
|
||||
| guildMemberAdd(guild, member) | guildMemberAdd(member) |
|
||||
| guildMemberAvailable(guild, member) | guildMemberAvailable(member) |
|
||||
| guildMemberRemove(guild, member) | guildMemberRemove(member) |
|
||||
| guildMembersChunk(guild, members) | guildMembersChunk(members) |
|
||||
| guildMemberUpdate(guild, oldMember, newMember) | guildMemberUpdate(oldMember, newMember) |
|
||||
| guildRoleCreate(guild, role) | roleCreate(role) |
|
||||
| guildRoleDelete(guild, role) | roleDelete(role) |
|
||||
| guildRoleUpdate(guild, oldRole, newRole) | roleUpdate(oldRole, newRole) |
|
||||
|
||||
The guild parameter that has been dropped from the guild-related events can still be derived using `member.guild` or `role.guild`.
|
||||
|
||||
### VoiceConnection events
|
||||
|
||||
| Version 9 | Version 10 |
|
||||
| ------------ | ---------- |
|
||||
| disconnected | disconnect |
|
||||
|
||||
## Dates and timestamps
|
||||
|
||||
All dates/timestamps on the structures have been refactored to have a consistent naming scheme and availability.
|
||||
All of them are named similarly to this:
|
||||
**Date:** `Message.createdAt`
|
||||
**Timestamp:** `Message.createdTimestamp`
|
||||
See the docs for each structure to see which date/timestamps are available on them.
|
||||
|
||||
# Version 9
|
||||
|
||||
The version 9 (v9) rewrite takes a much more object-oriented approach than previous versions,
|
||||
which allows your code to be much more readable and manageable.
|
||||
It's been rebuilt from the ground up and should be much more stable, fixing caching issues that affected
|
||||
older versions. It also has support for newer Discord Features, such as emojis.
|
||||
|
||||
Version 9, while containing a sizable number of breaking changes, does not require much change in your code's logic -
|
||||
most of the concepts are still the same, but loads of functions have been moved around.
|
||||
The vast majority of methods you're used to using have been moved out of the Client class,
|
||||
into other more relevant classes where they belong.
|
||||
Because of this, you will need to convert most of your calls over to the new methods.
|
||||
|
||||
Here are a few examples of methods that have changed:
|
||||
|
||||
- `Client.sendMessage(channel, message)` ==> `TextChannel.sendMessage(message)`
|
||||
- `Client.sendMessage(user, message)` ==> `User.sendMessage(message)`
|
||||
- `Client.updateMessage(message, "New content")` ==> `Message.edit("New Content")`
|
||||
- `Client.getChannelLogs(channel, limit)` ==> `TextChannel.fetchMessages({options})`
|
||||
- `Server.detailsOfUser(User)` ==> `Server.members.get(User).properties` (retrieving a member gives a GuildMember object)
|
||||
- `Client.joinVoiceChannel(voicechannel)` => `VoiceChannel.join()`
|
||||
|
||||
A couple more important details:
|
||||
|
||||
- `Client.loginWithToken("token")` ==> `client.login("token")`
|
||||
- `Client.servers.length` ==> `client.guilds.size` (all instances of `server` are now `guild`)
|
||||
|
||||
## No more callbacks!
|
||||
|
||||
Version 9 eschews callbacks in favour of Promises. This means all code relying on callbacks must be changed.
|
||||
For example, the following code:
|
||||
|
||||
```js
|
||||
client.getChannelLogs(channel, 100, function(messages) {
|
||||
console.log(`${messages.length} messages found`);
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
channel.fetchMessages({ limit: 100 }).then(messages => {
|
||||
console.log(`${messages.size} messages found`);
|
||||
});
|
||||
```
|
||||
@@ -1,103 +0,0 @@
|
||||
<div align="center">
|
||||
<br />
|
||||
<p>
|
||||
<a href="https://discord.js.org"><img src="/static/logo.svg" width="546" alt="discord.js" id="djs-logo" /></a>
|
||||
</p>
|
||||
<br />
|
||||
<p>
|
||||
<a href="https://discord.gg/bRCvFy9"><img src="https://discordapp.com/api/guilds/222078108977594368/embed.png" alt="Discord server" /></a>
|
||||
<a href="https://www.npmjs.com/package/discord.js"><img src="https://img.shields.io/npm/v/discord.js.svg?maxAge=3600" alt="NPM version" /></a>
|
||||
<a href="https://www.npmjs.com/package/discord.js"><img src="https://img.shields.io/npm/dt/discord.js.svg?maxAge=3600" alt="NPM downloads" /></a>
|
||||
<a href="https://travis-ci.org/discordjs/discord.js"><img src="https://travis-ci.org/discordjs/discord.js.svg" alt="Build status" /></a>
|
||||
<a href="https://david-dm.org/discordjs/discord.js"><img src="https://img.shields.io/david/discordjs/discord.js.svg?maxAge=3600" alt="Dependencies" /></a>
|
||||
<a href="https://www.patreon.com/discordjs"><img src="https://img.shields.io/badge/donate-patreon-F96854.svg" alt="Patreon" /></a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://nodei.co/npm/discord.js/"><img src="https://nodei.co/npm/discord.js.png?downloads=true&stars=true" alt="NPM info" /></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
# Welcome!
|
||||
|
||||
Welcome to the discord.js v12 documentation.
|
||||
|
||||
## About
|
||||
|
||||
discord.js is a powerful [Node.js](https://nodejs.org) module that allows you to easily interact with the
|
||||
[Discord API](https://discordapp.com/developers/docs/intro).
|
||||
|
||||
- Object-oriented
|
||||
- Predictable abstractions
|
||||
- Performant
|
||||
- 100% coverage of the Discord API
|
||||
|
||||
## Installation
|
||||
|
||||
**Node.js 12.0.0 or newer is required.**
|
||||
Ignore any warnings about unmet peer dependencies, as they're all optional.
|
||||
|
||||
Without voice support: `npm install discord.js`
|
||||
With voice support ([@discordjs/opus](https://www.npmjs.com/package/@discordjs/opus)): `npm install discord.js @discordjs/opus`
|
||||
With voice support ([opusscript](https://www.npmjs.com/package/opusscript)): `npm install discord.js opusscript`
|
||||
|
||||
### Audio engines
|
||||
|
||||
The preferred audio engine is @discordjs/opus, as it performs significantly better than opusscript. When both are available, discord.js will automatically choose @discordjs/opus.
|
||||
Using opusscript is only recommended for development environments where @discordjs/opus is tough to get working.
|
||||
For production bots, using @discordjs/opus should be considered a necessity, especially if they're going to be running on multiple servers.
|
||||
|
||||
### Optional packages
|
||||
|
||||
- [zlib-sync](https://www.npmjs.com/package/zlib-sync) for WebSocket data compression and inflation (`npm install zlib-sync`)
|
||||
- [erlpack](https://github.com/discordapp/erlpack) for significantly faster WebSocket data (de)serialisation (`npm install discordapp/erlpack`)
|
||||
- One of the following packages can be installed for faster voice packet encryption and decryption:
|
||||
- [sodium](https://www.npmjs.com/package/sodium) (`npm install sodium`)
|
||||
- [libsodium.js](https://www.npmjs.com/package/libsodium-wrappers) (`npm install libsodium-wrappers`)
|
||||
- [bufferutil](https://www.npmjs.com/package/bufferutil) for a much faster WebSocket connection (`npm install bufferutil`)
|
||||
- [utf-8-validate](https://www.npmjs.com/package/utf-8-validate) in combination with `bufferutil` for much faster WebSocket processing (`npm install utf-8-validate`)
|
||||
|
||||
## Example usage
|
||||
|
||||
```js
|
||||
const Discord = require('discord.js');
|
||||
const client = new Discord.Client();
|
||||
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
});
|
||||
|
||||
client.on('message', msg => {
|
||||
if (msg.content === 'ping') {
|
||||
msg.reply('pong');
|
||||
}
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
```
|
||||
|
||||
## Links
|
||||
|
||||
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/website))
|
||||
- [Documentation](https://discord.js.org/#/docs/main/master/general/welcome)
|
||||
- [Guide](https://discordjs.guide/) ([source](https://github.com/discordjs/guide)) - this is still for stable
|
||||
See also the WIP [Update Guide](https://discordjs.guide/additional-info/changes-in-v12.html) also including updated and removed items in the library.
|
||||
- [Discord.js Discord server](https://discord.gg/bRCvFy9)
|
||||
- [Discord API Discord server](https://discord.gg/discord-api)
|
||||
- [GitHub](https://github.com/discordjs/discord.js)
|
||||
- [NPM](https://www.npmjs.com/package/discord.js)
|
||||
- [Related libraries](https://discordapi.com/unofficial/libs.html)
|
||||
|
||||
### Extensions
|
||||
|
||||
- [RPC](https://www.npmjs.com/package/discord-rpc) ([source](https://github.com/discordjs/RPC))
|
||||
|
||||
## Contributing
|
||||
|
||||
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
|
||||
[documentation](https://discord.js.org/#/docs).
|
||||
See [the contribution guide](https://github.com/discordjs/discord.js/blob/master/.github/CONTRIBUTING.md) if you'd like to submit a PR.
|
||||
|
||||
## Help
|
||||
|
||||
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle
|
||||
nudge in the right direction, please don't hesitate to join our official [Discord.js Server](https://discord.gg/bRCvFy9).
|
||||
@@ -1,32 +1,5 @@
|
||||
- name: General
|
||||
files:
|
||||
- name: Welcome
|
||||
path: welcome.md
|
||||
- name: Updating your code
|
||||
path: updating.md
|
||||
- name: FAQ
|
||||
path: faq.md
|
||||
- name: Topics
|
||||
files:
|
||||
- name: Voice
|
||||
path: voice.md
|
||||
- name: Web builds
|
||||
path: web.md
|
||||
- name: Partials
|
||||
path: partials.md
|
||||
- name: Examples
|
||||
files:
|
||||
- name: Ping
|
||||
path: ping.js
|
||||
- name: Avatars
|
||||
path: avatars.js
|
||||
- name: Attachments
|
||||
path: attachments.md
|
||||
- name: Server greeting
|
||||
path: greeting.js
|
||||
- name: Message Embed
|
||||
path: embed.js
|
||||
- name: Moderation
|
||||
path: moderation.md
|
||||
- name: Webhook
|
||||
path: webhook.js
|
||||
id: welcome
|
||||
path: ../../README.md
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
# Partials
|
||||
|
||||
Partials allow you to receive events that contain uncached instances, providing structures that contain very minimal
|
||||
data. For example, if you were to receive a `messageDelete` event with an uncached message, normally Discord.js would
|
||||
discard the event. With partials, you're able to receive the event, with a Message object that contains just an ID.
|
||||
|
||||
## Opting in
|
||||
|
||||
Partials are opt-in, and you can enable them in the Client options by specifying [PartialTypes](/#/docs/main/master/typedef/PartialType):
|
||||
|
||||
```js
|
||||
// Accept partial messages, DM channels, and reactions when emitting events
|
||||
new Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
|
||||
```
|
||||
|
||||
## Usage & warnings
|
||||
|
||||
<warn>The only guaranteed data a partial structure can store is its ID. All other properties/methods should be
|
||||
considered invalid/defunct while accessing a partial structure.</warn>
|
||||
|
||||
After opting-in with the above, you begin to allow partial messages and channels in your caches, so it's important
|
||||
to check whether they're safe to access whenever you encounter them, whether it be in events or through normal cache
|
||||
usage.
|
||||
|
||||
All instance of structures that you opted-in for will have a `partial` property. As you'd expect, this value is `true`
|
||||
when the instance is partial. Partial structures are only guaranteed to contain an ID, any other properties and methods
|
||||
no longer carry their normal type guarantees.
|
||||
|
||||
This means you have to take time to consider possible parts of your program that might need checks put in place to
|
||||
prevent accessing partial data:
|
||||
|
||||
```js
|
||||
client.on('messageDelete', message => {
|
||||
console.log(`${message.id} was deleted!`);
|
||||
// Partial messages do not contain any content so skip them
|
||||
if (!message.partial) {
|
||||
console.log(`It had content: "${message.content}"`);
|
||||
}
|
||||
});
|
||||
|
||||
// You can also try to upgrade partials to full instances:
|
||||
client.on('messageReactionAdd', async (reaction, user) => {
|
||||
// If a message gains a reaction and it is uncached, fetch and cache the message
|
||||
// You should account for any errors while fetching, it could return API errors if the resource is missing
|
||||
if (reaction.message.partial) await reaction.message.fetch();
|
||||
// Now the message has been cached and is fully available:
|
||||
console.log(`${reaction.message.author}'s message "${reaction.message.content}" gained a reaction!`);
|
||||
// Fetches and caches the reaction itself, updating resources that were possibly defunct.
|
||||
if (reaction.partial) await reaction.fetch();
|
||||
// Now the reaction is fully available and the properties will be reflected accurately:
|
||||
console.log(`${reaction.count} user(s) have given the same reaction to this message!`);
|
||||
});
|
||||
```
|
||||
|
||||
<info>If a message is deleted and both the message and channel are uncached, you must enable both 'MESSAGE' and
|
||||
'CHANNEL' in the client options to receive the messageDelete event.</info>
|
||||
|
||||
## Why?
|
||||
|
||||
This allows developers to listen to events that contain uncached data, which is useful if you're running a moderation
|
||||
bot or any bot that relies on still receiving updates to resources you don't have cached -- message reactions are a
|
||||
good example.
|
||||
|
||||
Currently, the only type of channel that can be uncached is a DM channel, there is no reason why guild channels should
|
||||
not be cached.
|
||||
@@ -1,140 +0,0 @@
|
||||
# Introduction to Voice
|
||||
|
||||
Voice in discord.js can be used for many things, such as music bots, recording or relaying audio.
|
||||
|
||||
In discord.js, you can use voice by connecting to a `VoiceChannel` to obtain a `VoiceConnection`, where you can start streaming and receiving audio.
|
||||
|
||||
To get started, make sure you have:
|
||||
|
||||
- FFmpeg - `npm install ffmpeg-static`
|
||||
- an opus encoder, choose one from below:
|
||||
- `npm install @discordjs/opus` (better performance)
|
||||
- `npm install opusscript`
|
||||
- a good network connection
|
||||
|
||||
The preferred opus engine is @discordjs/opus, as it performs significantly better than opusscript. When both are available, discord.js will automatically choose @discordjs/opus.
|
||||
Using opusscript is only recommended for development environments where @discordjs/opus is tough to get working.
|
||||
For production bots, using @discordjs/opus should be considered a necessity, especially if they're going to be running on multiple servers.
|
||||
|
||||
## Joining a voice channel
|
||||
|
||||
The example below reacts to a message and joins the sender's voice channel, catching any errors. This is important
|
||||
as it allows us to obtain a `VoiceConnection` that we can start to stream audio with.
|
||||
|
||||
```js
|
||||
const Discord = require('discord.js');
|
||||
const client = new Discord.Client();
|
||||
|
||||
client.login('token here');
|
||||
|
||||
client.on('message', async message => {
|
||||
// Voice only works in guilds, if the message does not come from a guild,
|
||||
// we ignore it
|
||||
if (!message.guild) return;
|
||||
|
||||
if (message.content === '/join') {
|
||||
// Only try to join the sender's voice channel if they are in one themselves
|
||||
if (message.member.voice.channel) {
|
||||
const connection = await message.member.voice.channel.join();
|
||||
} else {
|
||||
message.reply('You need to join a voice channel first!');
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
## Streaming to a Voice Channel
|
||||
|
||||
In the previous example, we looked at how to join a voice channel in order to obtain a `VoiceConnection`. Now that we
|
||||
have obtained a voice connection, we can start streaming audio to it.
|
||||
|
||||
### Introduction to playing on voice connections
|
||||
|
||||
The most basic example of playing audio over a connection would be playing a local file:
|
||||
|
||||
```js
|
||||
const dispatcher = connection.play('/home/discord/audio.mp3');
|
||||
```
|
||||
|
||||
The `dispatcher` in this case is a `StreamDispatcher` - here you can control the volume and playback of the stream:
|
||||
|
||||
```js
|
||||
dispatcher.pause();
|
||||
dispatcher.resume();
|
||||
|
||||
dispatcher.setVolume(0.5); // half the volume
|
||||
|
||||
dispatcher.on('finish', () => {
|
||||
console.log('Finished playing!');
|
||||
});
|
||||
|
||||
dispatcher.destroy(); // end the stream
|
||||
```
|
||||
|
||||
We can also pass in options when we first play the stream:
|
||||
|
||||
```js
|
||||
const dispatcher = connection.play('/home/discord/audio.mp3', {
|
||||
volume: 0.5,
|
||||
});
|
||||
```
|
||||
|
||||
### What can I play?
|
||||
|
||||
Discord.js allows you to play a lot of things:
|
||||
|
||||
```js
|
||||
// ReadableStreams, in this example YouTube audio
|
||||
const ytdl = require('ytdl-core');
|
||||
connection.play(ytdl('https://www.youtube.com/watch?v=ZlAU_w7-Xp8', { filter: 'audioonly' }));
|
||||
|
||||
// Files on the internet
|
||||
connection.play('http://www.sample-videos.com/audio/mp3/wave.mp3');
|
||||
|
||||
// Local files
|
||||
connection.play('/home/discord/audio.mp3');
|
||||
```
|
||||
|
||||
New to v12 is the ability to play OggOpus and WebmOpus streams with much better performance by skipping out Ffmpeg. Note this comes at the cost of no longer having volume control over the stream:
|
||||
|
||||
```js
|
||||
connection.play(fs.createReadStream('./media.webm'), {
|
||||
type: 'webm/opus',
|
||||
});
|
||||
|
||||
connection.play(fs.createReadStream('./media.ogg'), {
|
||||
type: 'ogg/opus',
|
||||
});
|
||||
```
|
||||
|
||||
Make sure to consult the documentation for a full list of what you can play - there's too much to cover here!
|
||||
|
||||
## Voice Broadcasts
|
||||
|
||||
A voice broadcast is very useful for "radio" bots, that play the same audio across multiple channels. It means audio is only transcoded once, and is much better on performance.
|
||||
|
||||
```js
|
||||
const broadcast = client.voice.createBroadcast();
|
||||
|
||||
broadcast.on('subscribe', dispatcher => {
|
||||
console.log('New broadcast subscriber!');
|
||||
});
|
||||
|
||||
broadcast.on('unsubscribe', dispatcher => {
|
||||
console.log('Channel unsubscribed from broadcast :(');
|
||||
});
|
||||
```
|
||||
|
||||
`broadcast` is an instance of `VoiceBroadcast`, which has the same `play` method you are used to with regular VoiceConnections:
|
||||
|
||||
```js
|
||||
const dispatcher = broadcast.play('./audio.mp3');
|
||||
|
||||
connection.play(broadcast);
|
||||
```
|
||||
|
||||
It's important to note that the `dispatcher` stored above is a `BroadcastDispatcher` - it controls all the dispatcher subscribed to the broadcast, e.g. setting the volume of this dispatcher affects the volume of all subscribers.
|
||||
|
||||
## Voice Receive
|
||||
|
||||
coming soon™
|
||||
@@ -1,52 +0,0 @@
|
||||
# Web builds
|
||||
|
||||
In addition to your usual Node applications, discord.js has special distributions available that are capable of running in web browsers.
|
||||
This is useful for client-side web apps that need to interact with the Discord API.
|
||||
[Webpack 3](https://webpack.js.org/) is used to build these.
|
||||
|
||||
## Restrictions
|
||||
|
||||
- Any voice-related functionality is unavailable, as there is currently no audio encoding/decoding capabilities without external native libraries,
|
||||
which web browsers do not support.
|
||||
- The ShardingManager cannot be used, since it relies on being able to spawn child processes for shards.
|
||||
- None of the native optional packages are usable.
|
||||
|
||||
### Require Library
|
||||
|
||||
If you are making your own webpack project, you can require `discord.js/browser` wherever you need to use discord.js, like so:
|
||||
|
||||
```js
|
||||
const Discord = require('discord.js/browser');
|
||||
// do something with Discord like you normally would
|
||||
```
|
||||
|
||||
### Webpack File
|
||||
|
||||
You can obtain your desired version of discord.js' web build from the [webpack branch](https://github.com/discordjs/discord.js/tree/webpack) of the GitHub repository.
|
||||
There is a file for each branch and version of the library, and the ones ending in `.min.js` are minified to substantially reduce the size of the source code.
|
||||
|
||||
Include the file on the page just as you would any other JS library, like so:
|
||||
|
||||
```html
|
||||
<script type="text/javascript" src="discord.VERSION.min.js"></script>
|
||||
```
|
||||
|
||||
Rather than importing discord.js with `require('discord.js')`, the entire `Discord` object is available as a global (on the `window`) object.
|
||||
The usage of the API isn't any different from using it in Node.js.
|
||||
|
||||
#### Example
|
||||
|
||||
```html
|
||||
<script type="text/javascript" src="discord.11.1.0.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
const client = new Discord.Client();
|
||||
|
||||
client.on('message', msg => {
|
||||
const guildTag = msg.channel.type === 'text' ? `[${msg.guild.name}]` : '[DM]';
|
||||
const channelTag = msg.channel.type === 'text' ? `[#${msg.channel.name}]` : '';
|
||||
console.log(`${guildTag}${channelTag} ${msg.author.tag}: ${msg.content}`);
|
||||
});
|
||||
|
||||
client.login('some crazy token');
|
||||
</script>
|
||||
```
|
||||
20540
package-lock.json
generated
Normal file
20540
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
187
package.json
187
package.json
@@ -1,23 +1,37 @@
|
||||
{
|
||||
"name": "discord.js",
|
||||
"version": "12.0.2",
|
||||
"version": "13.1.0",
|
||||
"description": "A powerful library for interacting with the Discord API",
|
||||
"main": "./src/index",
|
||||
"main": "./src/index.js",
|
||||
"module": "./src/index.mjs",
|
||||
"types": "./typings/index.d.ts",
|
||||
"files": [
|
||||
"src",
|
||||
"typings"
|
||||
],
|
||||
"exports": {
|
||||
"./*": "./*",
|
||||
".": {
|
||||
"require": "./src/index.js",
|
||||
"import": "./src/index.mjs"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "npm run lint && npm run docs:test && npm run lint:typings",
|
||||
"test:typescript": "tsc",
|
||||
"docs": "docgen --source src --custom docs/index.yml --output docs/docs.json",
|
||||
"docs:test": "docgen --source src --custom docs/index.yml",
|
||||
"lint": "eslint src",
|
||||
"lint:fix": "eslint src --fix",
|
||||
"lint:typings": "tslint typings/index.d.ts",
|
||||
"prettier": "prettier --write --single-quote --print-width 120 --trailing-comma all --end-of-line lf src/**/*.js typings/**/*.ts",
|
||||
"build:browser": "webpack",
|
||||
"prepublishOnly": "npm run test && NODE_ENV=production npm run build:browser"
|
||||
"prettier": "prettier --write src/**/*.js typings/**/*.ts",
|
||||
"prepublishOnly": "npm run test && gen-esm-wrapper ./src/index.js ./src/index.mjs",
|
||||
"prepare": "is-ci || husky install",
|
||||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/discordjs/discord.js.git"
|
||||
"url": "https://github.com/discordjs/discord.js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"discord",
|
||||
@@ -27,146 +41,45 @@
|
||||
"node",
|
||||
"discordapp"
|
||||
],
|
||||
"author": "Amish Shah <amishshah.2k@gmail.com>",
|
||||
"author": "Amish Shah <amish@shah.gg>",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/discordjs/discord.js#readme",
|
||||
"runkitExampleFilename": "./docs/examples/ping.js",
|
||||
"unpkg": "./webpack/discord.min.js",
|
||||
"dependencies": {
|
||||
"@discordjs/collection": "^0.1.5",
|
||||
"abort-controller": "^3.0.0",
|
||||
"form-data": "^3.0.0",
|
||||
"node-fetch": "^2.6.0",
|
||||
"prism-media": "^1.2.0",
|
||||
"setimmediate": "^1.0.5",
|
||||
"tweetnacl": "^1.0.3",
|
||||
"ws": "^7.2.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"bufferutil": "^4.0.1",
|
||||
"erlpack": "discordapp/erlpack",
|
||||
"libsodium-wrappers": "^0.7.6",
|
||||
"sodium": "^3.0.2",
|
||||
"utf-8-validate": "^5.0.2",
|
||||
"zlib-sync": "^0.1.6"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"bufferutil": {
|
||||
"optional": true
|
||||
},
|
||||
"erlpack": {
|
||||
"optional": true
|
||||
},
|
||||
"libsodium-wrappers": {
|
||||
"optional": true
|
||||
},
|
||||
"sodium": {
|
||||
"optional": true
|
||||
},
|
||||
"utf-8-validate": {
|
||||
"optional": true
|
||||
},
|
||||
"zlib-sync": {
|
||||
"optional": true
|
||||
}
|
||||
"@discordjs/builders": "^0.5.0",
|
||||
"@discordjs/collection": "^0.2.1",
|
||||
"@discordjs/form-data": "^3.0.1",
|
||||
"@sapphire/async-queue": "^1.1.4",
|
||||
"@types/ws": "^7.4.7",
|
||||
"discord-api-types": "^0.22.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"ws": "^7.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^8.3.5",
|
||||
"@commitlint/config-angular": "^8.3.4",
|
||||
"@types/node": "^10.12.24",
|
||||
"@types/ws": "^7.2.1",
|
||||
"discord.js-docgen": "discordjs/docgen",
|
||||
"dtslint": "^3.0.0",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-config-prettier": "^6.10.0",
|
||||
"eslint-plugin-import": "^2.20.1",
|
||||
"eslint-plugin-prettier": "^3.1.2",
|
||||
"husky": "^4.2.3",
|
||||
"jest": "^25.1.0",
|
||||
"json-filter-loader": "^1.0.0",
|
||||
"lint-staged": "^10.0.8",
|
||||
"prettier": "^1.19.1",
|
||||
"terser-webpack-plugin": "^1.2.2",
|
||||
"tslint": "^6.0.0",
|
||||
"typescript": "^3.8.2",
|
||||
"webpack": "^4.41.6",
|
||||
"webpack-cli": "^3.3.11"
|
||||
"@commitlint/cli": "^13.1.0",
|
||||
"@commitlint/config-angular": "^13.1.0",
|
||||
"@discordjs/docgen": "^0.10.0",
|
||||
"@types/node": "^16.4.12",
|
||||
"conventional-changelog-cli": "^2.1.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"dtslint": "^4.1.3",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-import": "^2.23.4",
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"gen-esm-wrapper": "^1.1.2",
|
||||
"husky": "^7.0.1",
|
||||
"is-ci": "^3.0.0",
|
||||
"jest": "^27.0.6",
|
||||
"lint-staged": "^11.1.1",
|
||||
"prettier": "^2.3.2",
|
||||
"tslint": "^6.1.3",
|
||||
"typescript": "^4.3.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"browser": {
|
||||
"@discordjs/opus": false,
|
||||
"https": false,
|
||||
"ws": false,
|
||||
"erlpack": false,
|
||||
"prism-media": false,
|
||||
"opusscript": false,
|
||||
"node-opus": false,
|
||||
"tweetnacl": false,
|
||||
"sodium": false,
|
||||
"worker_threads": false,
|
||||
"zlib-sync": false,
|
||||
"src/sharding/Shard.js": false,
|
||||
"src/sharding/ShardClientUtil.js": false,
|
||||
"src/sharding/ShardingManager.js": false,
|
||||
"src/client/voice/ClientVoiceManager.js": false,
|
||||
"src/client/voice/VoiceBroadcast.js": false,
|
||||
"src/client/voice/VoiceConnection.js": false,
|
||||
"src/client/voice/dispatcher/BroadcastDispatcher.js": false,
|
||||
"src/client/voice/dispatcher/StreamDispatcher.js": false,
|
||||
"src/client/voice/networking/VoiceUDPClient.js": false,
|
||||
"src/client/voice/networking/VoiceWebSocket.js": false,
|
||||
"src/client/voice/player/AudioPlayer.js": false,
|
||||
"src/client/voice/player/BasePlayer.js": false,
|
||||
"src/client/voice/player/BroadcastAudioPlayer.js": false,
|
||||
"src/client/voice/receiver/PacketHandler.js": false,
|
||||
"src/client/voice/receiver/Receiver.js": false,
|
||||
"src/client/voice/util/PlayInterface.js": false,
|
||||
"src/client/voice/util/Secretbox.js": false,
|
||||
"src/client/voice/util/Silence.js": false,
|
||||
"src/client/voice/util/VolumeInterface.js": false
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "lint-staged",
|
||||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.js": "eslint --fix",
|
||||
"*.ts": "prettier --write --single-quote --print-width 120 --trailing-comma all --end-of-line lf"
|
||||
},
|
||||
"commitlint": {
|
||||
"extends": [
|
||||
"@commitlint/config-angular"
|
||||
],
|
||||
"rules": {
|
||||
"scope-case": [
|
||||
2,
|
||||
"always",
|
||||
"pascal-case"
|
||||
],
|
||||
"type-enum": [
|
||||
2,
|
||||
"always",
|
||||
[
|
||||
"chore",
|
||||
"build",
|
||||
"ci",
|
||||
"docs",
|
||||
"feat",
|
||||
"fix",
|
||||
"perf",
|
||||
"refactor",
|
||||
"revert",
|
||||
"style",
|
||||
"test"
|
||||
]
|
||||
]
|
||||
}
|
||||
"node": ">=16.6.0",
|
||||
"npm": ">=7.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { browser } = require('./util/Constants');
|
||||
|
||||
let erlpack;
|
||||
|
||||
try {
|
||||
@@ -9,15 +7,7 @@ try {
|
||||
if (!erlpack.pack) erlpack = null;
|
||||
} catch {} // eslint-disable-line no-empty
|
||||
|
||||
let TextDecoder;
|
||||
|
||||
if (browser) {
|
||||
TextDecoder = window.TextDecoder; // eslint-disable-line no-undef
|
||||
exports.WebSocket = window.WebSocket; // eslint-disable-line no-undef
|
||||
} else {
|
||||
TextDecoder = require('util').TextDecoder;
|
||||
exports.WebSocket = require('ws');
|
||||
}
|
||||
exports.WebSocket = require('ws');
|
||||
|
||||
const ab = new TextDecoder();
|
||||
|
||||
@@ -42,7 +32,6 @@ exports.create = (gateway, query = {}, ...args) => {
|
||||
query = new URLSearchParams(query);
|
||||
if (q) new URLSearchParams(q).forEach((v, k) => query.set(k, v));
|
||||
const ws = new exports.WebSocket(`${g}?${query}`, ...args);
|
||||
if (browser) ws.binaryType = 'arraybuffer';
|
||||
return ws;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
require('setimmediate');
|
||||
const EventEmitter = require('events');
|
||||
const RESTManager = require('../rest/RESTManager');
|
||||
const { DefaultOptions } = require('../util/Constants');
|
||||
const Options = require('../util/Options');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
/**
|
||||
@@ -14,32 +13,11 @@ class BaseClient extends EventEmitter {
|
||||
constructor(options = {}) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* Timeouts set by {@link BaseClient#setTimeout} that are still active
|
||||
* @type {Set<Timeout>}
|
||||
* @private
|
||||
*/
|
||||
this._timeouts = new Set();
|
||||
|
||||
/**
|
||||
* Intervals set by {@link BaseClient#setInterval} that are still active
|
||||
* @type {Set<Timeout>}
|
||||
* @private
|
||||
*/
|
||||
this._intervals = new Set();
|
||||
|
||||
/**
|
||||
* Intervals set by {@link BaseClient#setImmediate} that are still active
|
||||
* @type {Set<Immediate>}
|
||||
* @private
|
||||
*/
|
||||
this._immediates = new Set();
|
||||
|
||||
/**
|
||||
* The options the client was instantiated with
|
||||
* @type {ClientOptions}
|
||||
*/
|
||||
this.options = Util.mergeDefault(DefaultOptions, options);
|
||||
this.options = Util.mergeDefault(Options.createDefault(), options);
|
||||
|
||||
/**
|
||||
* The REST manager of the client
|
||||
@@ -61,82 +39,32 @@ class BaseClient extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Destroys all assets used by the base client.
|
||||
* @returns {void}
|
||||
*/
|
||||
destroy() {
|
||||
for (const t of this._timeouts) this.clearTimeout(t);
|
||||
for (const i of this._intervals) this.clearInterval(i);
|
||||
for (const i of this._immediates) this.clearImmediate(i);
|
||||
this._timeouts.clear();
|
||||
this._intervals.clear();
|
||||
this._immediates.clear();
|
||||
if (this.rest.sweepInterval) clearInterval(this.rest.sweepInterval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a timeout that will be automatically cancelled if the client is destroyed.
|
||||
* @param {Function} fn Function to execute
|
||||
* @param {number} delay Time to wait before executing (in milliseconds)
|
||||
* @param {...*} args Arguments for the function
|
||||
* @returns {Timeout}
|
||||
* Increments max listeners by one, if they are not zero.
|
||||
* @private
|
||||
*/
|
||||
setTimeout(fn, delay, ...args) {
|
||||
const timeout = setTimeout(() => {
|
||||
fn(...args);
|
||||
this._timeouts.delete(timeout);
|
||||
}, delay);
|
||||
this._timeouts.add(timeout);
|
||||
return timeout;
|
||||
incrementMaxListeners() {
|
||||
const maxListeners = this.getMaxListeners();
|
||||
if (maxListeners !== 0) {
|
||||
this.setMaxListeners(maxListeners + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears a timeout.
|
||||
* @param {Timeout} timeout Timeout to cancel
|
||||
* Decrements max listeners by one, if they are not zero.
|
||||
* @private
|
||||
*/
|
||||
clearTimeout(timeout) {
|
||||
clearTimeout(timeout);
|
||||
this._timeouts.delete(timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an interval that will be automatically cancelled if the client is destroyed.
|
||||
* @param {Function} fn Function to execute
|
||||
* @param {number} delay Time to wait between executions (in milliseconds)
|
||||
* @param {...*} args Arguments for the function
|
||||
* @returns {Timeout}
|
||||
*/
|
||||
setInterval(fn, delay, ...args) {
|
||||
const interval = setInterval(fn, delay, ...args);
|
||||
this._intervals.add(interval);
|
||||
return interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears an interval.
|
||||
* @param {Timeout} interval Interval to cancel
|
||||
*/
|
||||
clearInterval(interval) {
|
||||
clearInterval(interval);
|
||||
this._intervals.delete(interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an immediate that will be automatically cancelled if the client is destroyed.
|
||||
* @param {Function} fn Function to execute
|
||||
* @param {...*} args Arguments for the function
|
||||
* @returns {Immediate}
|
||||
*/
|
||||
setImmediate(fn, ...args) {
|
||||
const immediate = setImmediate(fn, ...args);
|
||||
this._immediates.add(immediate);
|
||||
return immediate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears an immediate.
|
||||
* @param {Immediate} immediate Immediate to cancel
|
||||
*/
|
||||
clearImmediate(immediate) {
|
||||
clearImmediate(immediate);
|
||||
this._immediates.delete(immediate);
|
||||
decrementMaxListeners() {
|
||||
const maxListeners = this.getMaxListeners();
|
||||
if (maxListeners !== 0) {
|
||||
this.setMaxListeners(maxListeners - 1);
|
||||
}
|
||||
}
|
||||
|
||||
toJSON(...props) {
|
||||
|
||||
@@ -1,25 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const BaseClient = require('./BaseClient');
|
||||
const ActionsManager = require('./actions/ActionsManager');
|
||||
const ClientVoiceManager = require('./voice/ClientVoiceManager');
|
||||
const WebSocketManager = require('./websocket/WebSocketManager');
|
||||
const { Error, TypeError, RangeError } = require('../errors');
|
||||
const BaseGuildEmojiManager = require('../managers/BaseGuildEmojiManager');
|
||||
const ChannelManager = require('../managers/ChannelManager');
|
||||
const GuildEmojiManager = require('../managers/GuildEmojiManager');
|
||||
const GuildManager = require('../managers/GuildManager');
|
||||
const UserManager = require('../managers/UserManager');
|
||||
const ShardClientUtil = require('../sharding/ShardClientUtil');
|
||||
const ClientApplication = require('../structures/ClientApplication');
|
||||
const ClientPresence = require('../structures/ClientPresence');
|
||||
const GuildPreview = require('../structures/GuildPreview');
|
||||
const GuildTemplate = require('../structures/GuildTemplate');
|
||||
const Invite = require('../structures/Invite');
|
||||
const Sticker = require('../structures/Sticker');
|
||||
const StickerPack = require('../structures/StickerPack');
|
||||
const VoiceRegion = require('../structures/VoiceRegion');
|
||||
const Webhook = require('../structures/Webhook');
|
||||
const Collection = require('../util/Collection');
|
||||
const { Events, browser, DefaultOptions } = require('../util/Constants');
|
||||
const Widget = require('../structures/Widget');
|
||||
const { Events, InviteScopes, Status } = require('../util/Constants');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const Intents = require('../util/Intents');
|
||||
const Options = require('../util/Options');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const Structures = require('../util/Structures');
|
||||
|
||||
/**
|
||||
* The main hub for interacting with the Discord API, and the starting point for any bot.
|
||||
@@ -27,27 +32,21 @@ const Structures = require('../util/Structures');
|
||||
*/
|
||||
class Client extends BaseClient {
|
||||
/**
|
||||
* @param {ClientOptions} [options] Options for the client
|
||||
* @param {ClientOptions} options Options for the client
|
||||
*/
|
||||
constructor(options = {}) {
|
||||
constructor(options) {
|
||||
super(Object.assign({ _tokenType: 'Bot' }, options));
|
||||
|
||||
// Obtain shard details from environment or if present, worker threads
|
||||
let data = process.env;
|
||||
try {
|
||||
// Test if worker threads module is present and used
|
||||
data = require('worker_threads').workerData || data;
|
||||
} catch {
|
||||
// Do nothing
|
||||
}
|
||||
const data = require('worker_threads').workerData ?? process.env;
|
||||
const defaults = Options.createDefault();
|
||||
|
||||
if (this.options.shards === DefaultOptions.shards) {
|
||||
if (this.options.shards === defaults.shards) {
|
||||
if ('SHARDS' in data) {
|
||||
this.options.shards = JSON.parse(data.SHARDS);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.options.shardCount === DefaultOptions.shardCount) {
|
||||
if (this.options.shardCount === defaults.shardCount) {
|
||||
if ('SHARD_COUNT' in data) {
|
||||
this.options.shardCount = Number(data.SHARD_COUNT);
|
||||
} else if (Array.isArray(this.options.shards)) {
|
||||
@@ -73,6 +72,20 @@ class Client extends BaseClient {
|
||||
|
||||
this._validateOptions();
|
||||
|
||||
/**
|
||||
* Functions called when a cache is garbage collected or the Client is destroyed
|
||||
* @type {Set<Function>}
|
||||
* @private
|
||||
*/
|
||||
this._cleanups = new Set();
|
||||
|
||||
/**
|
||||
* The finalizers used to cleanup items.
|
||||
* @type {FinalizationRegistry}
|
||||
* @private
|
||||
*/
|
||||
this._finalizers = new FinalizationRegistry(this._finalize.bind(this));
|
||||
|
||||
/**
|
||||
* The WebSocket manager of the client
|
||||
* @type {WebSocketManager}
|
||||
@@ -87,35 +100,34 @@ class Client extends BaseClient {
|
||||
this.actions = new ActionsManager(this);
|
||||
|
||||
/**
|
||||
* The voice manager of the client (`null` in browsers)
|
||||
* @type {?ClientVoiceManager}
|
||||
* The voice manager of the client
|
||||
* @type {ClientVoiceManager}
|
||||
*/
|
||||
this.voice = !browser ? new ClientVoiceManager(this) : null;
|
||||
this.voice = new ClientVoiceManager(this);
|
||||
|
||||
/**
|
||||
* Shard helpers for the client (only if the process was spawned from a {@link ShardingManager})
|
||||
* @type {?ShardClientUtil}
|
||||
*/
|
||||
this.shard =
|
||||
!browser && process.env.SHARDING_MANAGER
|
||||
? ShardClientUtil.singleton(this, process.env.SHARDING_MANAGER_MODE)
|
||||
: null;
|
||||
this.shard = process.env.SHARDING_MANAGER
|
||||
? ShardClientUtil.singleton(this, process.env.SHARDING_MANAGER_MODE)
|
||||
: null;
|
||||
|
||||
/**
|
||||
* All of the {@link User} objects that have been cached at any point, mapped by their IDs
|
||||
* All of the {@link User} objects that have been cached at any point, mapped by their ids
|
||||
* @type {UserManager}
|
||||
*/
|
||||
this.users = new UserManager(this);
|
||||
|
||||
/**
|
||||
* All of the guilds the client is currently handling, mapped by their IDs -
|
||||
* All of the guilds the client is currently handling, mapped by their ids -
|
||||
* as long as sharding isn't being used, this will be *every* guild the bot is a member of
|
||||
* @type {GuildManager}
|
||||
*/
|
||||
this.guilds = new GuildManager(this);
|
||||
|
||||
/**
|
||||
* All of the {@link Channel}s that the client is currently handling, mapped by their IDs -
|
||||
* All of the {@link Channel}s that the client is currently handling, mapped by their ids -
|
||||
* as long as sharding isn't being used, this will be *every* channel in *every* guild the bot
|
||||
* is a member of. Note that DM channels will not be initially cached, and thus not be present
|
||||
* in the Manager without their explicit fetching or use.
|
||||
@@ -123,18 +135,18 @@ class Client extends BaseClient {
|
||||
*/
|
||||
this.channels = new ChannelManager(this);
|
||||
|
||||
const ClientPresence = Structures.get('ClientPresence');
|
||||
/**
|
||||
* The presence of the Client
|
||||
* @private
|
||||
* @type {ClientPresence}
|
||||
*/
|
||||
this.presence = new ClientPresence(this);
|
||||
this.presence = new ClientPresence(this, this.options.presence);
|
||||
|
||||
Object.defineProperty(this, 'token', { writable: true });
|
||||
if (!browser && !this.token && 'DISCORD_TOKEN' in process.env) {
|
||||
if (!this.token && 'DISCORD_TOKEN' in process.env) {
|
||||
/**
|
||||
* Authorization token for the logged in bot
|
||||
* Authorization token for the logged in bot.
|
||||
* If present, this defaults to `process.env.DISCORD_TOKEN` when instantiating the client
|
||||
* <warn>This should be kept private at all times.</warn>
|
||||
* @type {?string}
|
||||
*/
|
||||
@@ -149,6 +161,12 @@ class Client extends BaseClient {
|
||||
*/
|
||||
this.user = null;
|
||||
|
||||
/**
|
||||
* The application of this bot
|
||||
* @type {?ClientApplication}
|
||||
*/
|
||||
this.application = null;
|
||||
|
||||
/**
|
||||
* Time at which the client was last regarded as being in the `READY` state
|
||||
* (each time the client disconnects and successfully reconnects, this will be overwritten)
|
||||
@@ -157,17 +175,24 @@ class Client extends BaseClient {
|
||||
this.readyAt = null;
|
||||
|
||||
if (this.options.messageSweepInterval > 0) {
|
||||
this.setInterval(this.sweepMessages.bind(this), this.options.messageSweepInterval * 1000);
|
||||
process.emitWarning(
|
||||
'The message sweeping client options are deprecated, use the makeCache option with LimitedCollection instead.',
|
||||
'DeprecationWarning',
|
||||
);
|
||||
this.sweepMessageInterval = setInterval(
|
||||
this.sweepMessages.bind(this),
|
||||
this.options.messageSweepInterval * 1000,
|
||||
).unref();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All custom emojis that the client has access to, mapped by their IDs
|
||||
* @type {GuildEmojiManager}
|
||||
* All custom emojis that the client has access to, mapped by their ids
|
||||
* @type {BaseGuildEmojiManager}
|
||||
* @readonly
|
||||
*/
|
||||
get emojis() {
|
||||
const emojis = new GuildEmojiManager({ client: this });
|
||||
const emojis = new BaseGuildEmojiManager(this);
|
||||
for (const guild of this.guilds.cache.values()) {
|
||||
if (guild.available) for (const emoji of guild.emojis.cache.values()) emojis.cache.set(emoji.id, emoji);
|
||||
}
|
||||
@@ -180,7 +205,7 @@ class Client extends BaseClient {
|
||||
* @readonly
|
||||
*/
|
||||
get readyTimestamp() {
|
||||
return this.readyAt ? this.readyAt.getTime() : null;
|
||||
return this.readyAt?.getTime() ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +219,7 @@ class Client extends BaseClient {
|
||||
|
||||
/**
|
||||
* Logs the client in, establishing a websocket connection to Discord.
|
||||
* @param {string} token Token of the account to log in with
|
||||
* @param {string} [token=this.token] Token of the account to log in with
|
||||
* @returns {Promise<string>} Token of the account used
|
||||
* @example
|
||||
* client.login('my token');
|
||||
@@ -211,7 +236,7 @@ class Client extends BaseClient {
|
||||
);
|
||||
|
||||
if (this.options.presence) {
|
||||
this.options.ws.presence = await this.presence._parse(this.options.presence);
|
||||
this.options.ws.presence = this.presence._parse(this.options.presence);
|
||||
}
|
||||
|
||||
this.emit(Events.DEBUG, 'Preparing to connect to the gateway...');
|
||||
@@ -225,12 +250,27 @@ class Client extends BaseClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the client has logged in, indicative of being able to access
|
||||
* properties such as `user` and `application`.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isReady() {
|
||||
return this.ws.status === Status.READY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out, terminates the connection to Discord, and destroys the client.
|
||||
* @returns {void}
|
||||
*/
|
||||
destroy() {
|
||||
super.destroy();
|
||||
|
||||
for (const fn of this._cleanups) fn();
|
||||
this._cleanups.clear();
|
||||
|
||||
if (this.sweepMessageInterval) clearInterval(this.sweepMessageInterval);
|
||||
|
||||
this.ws.destroy();
|
||||
this.token = null;
|
||||
}
|
||||
@@ -240,21 +280,34 @@ class Client extends BaseClient {
|
||||
* @param {InviteResolvable} invite Invite code or URL
|
||||
* @returns {Promise<Invite>}
|
||||
* @example
|
||||
* client.fetchInvite('https://discord.gg/bRCvFy9')
|
||||
* client.fetchInvite('https://discord.gg/djs')
|
||||
* .then(invite => console.log(`Obtained invite with code: ${invite.code}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchInvite(invite) {
|
||||
async fetchInvite(invite) {
|
||||
const code = DataResolver.resolveInviteCode(invite);
|
||||
return this.api
|
||||
.invites(code)
|
||||
.get({ query: { with_counts: true } })
|
||||
.then(data => new Invite(this, data));
|
||||
const data = await this.api.invites(code).get({ query: { with_counts: true, with_expiration: true } });
|
||||
return new Invite(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a template from Discord.
|
||||
* @param {GuildTemplateResolvable} template Template code or URL
|
||||
* @returns {Promise<GuildTemplate>}
|
||||
* @example
|
||||
* client.fetchGuildTemplate('https://discord.new/FKvmczH2HyUf')
|
||||
* .then(template => console.log(`Obtained template with code: ${template.code}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetchGuildTemplate(template) {
|
||||
const code = DataResolver.resolveGuildTemplateCode(template);
|
||||
const data = await this.api.guilds.templates(code).get();
|
||||
return new GuildTemplate(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a webhook from Discord.
|
||||
* @param {Snowflake} id ID of the webhook
|
||||
* @param {Snowflake} id The webhook's id
|
||||
* @param {string} [token] Token for the webhook
|
||||
* @returns {Promise<Webhook>}
|
||||
* @example
|
||||
@@ -262,11 +315,9 @@ class Client extends BaseClient {
|
||||
* .then(webhook => console.log(`Obtained webhook with name: ${webhook.name}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchWebhook(id, token) {
|
||||
return this.api
|
||||
.webhooks(id, token)
|
||||
.get()
|
||||
.then(data => new Webhook(this, data));
|
||||
async fetchWebhook(id, token) {
|
||||
const data = await this.api.webhooks(id, token).get();
|
||||
return new Webhook(this, { token, ...data });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,12 +328,56 @@ class Client extends BaseClient {
|
||||
* .then(regions => console.log(`Available regions are: ${regions.map(region => region.name).join(', ')}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchVoiceRegions() {
|
||||
return this.api.voice.regions.get().then(res => {
|
||||
const regions = new Collection();
|
||||
for (const region of res) regions.set(region.id, new VoiceRegion(region));
|
||||
return regions;
|
||||
});
|
||||
async fetchVoiceRegions() {
|
||||
const apiRegions = await this.api.voice.regions.get();
|
||||
const regions = new Collection();
|
||||
for (const region of apiRegions) regions.set(region.id, new VoiceRegion(region));
|
||||
return regions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a sticker from Discord.
|
||||
* @param {Snowflake} id The sticker's id
|
||||
* @returns {Promise<Sticker>}
|
||||
* @example
|
||||
* client.fetchSticker('id')
|
||||
* .then(sticker => console.log(`Obtained sticker with name: ${sticker.name}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetchSticker(id) {
|
||||
const data = await this.api.stickers(id).get();
|
||||
return new Sticker(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the list of sticker packs available to Nitro subscribers from Discord.
|
||||
* @returns {Promise<Collection<Snowflake, StickerPack>>}
|
||||
* @example
|
||||
* client.fetchPremiumStickerPacks()
|
||||
* .then(packs => console.log(`Available sticker packs are: ${packs.map(pack => pack.name).join(', ')}`))
|
||||
* .catch(console.error);
|
||||
*/
|
||||
async fetchPremiumStickerPacks() {
|
||||
const data = await this.api('sticker-packs').get();
|
||||
return new Collection(data.sticker_packs.map(p => [p.id, new StickerPack(this, p)]));
|
||||
}
|
||||
/**
|
||||
* A last ditch cleanup function for garbage collection.
|
||||
* @param {Function} options.cleanup The function called to GC
|
||||
* @param {string} [options.message] The message to send after a successful GC
|
||||
* @param {string} [options.name] The name of the item being GCed
|
||||
* @private
|
||||
*/
|
||||
_finalize({ cleanup, message, name }) {
|
||||
try {
|
||||
cleanup();
|
||||
this._cleanups.delete(cleanup);
|
||||
if (message) {
|
||||
this.emit(Events.DEBUG, message);
|
||||
}
|
||||
} catch {
|
||||
this.emit(Events.DEBUG, `Garbage collection failed on ${name ?? 'an unknown item'}.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,7 +411,7 @@ class Client extends BaseClient {
|
||||
channels++;
|
||||
|
||||
messages += channel.messages.cache.sweep(
|
||||
message => now - (message.editedTimestamp || message.createdTimestamp) > lifetimeMs,
|
||||
message => now - (message.editedTimestamp ?? message.createdTimestamp) > lifetimeMs,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -328,40 +423,103 @@ class Client extends BaseClient {
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the OAuth Application of this bot from Discord.
|
||||
* @returns {Promise<ClientApplication>}
|
||||
* Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
|
||||
* @param {GuildResolvable} guild The guild to fetch the preview for
|
||||
* @returns {Promise<GuildPreview>}
|
||||
*/
|
||||
fetchApplication() {
|
||||
return this.api.oauth2
|
||||
.applications('@me')
|
||||
.get()
|
||||
.then(app => new ClientApplication(this, app));
|
||||
async fetchGuildPreview(guild) {
|
||||
const id = this.guilds.resolveId(guild);
|
||||
if (!id) throw new TypeError('INVALID_TYPE', 'guild', 'GuildResolvable');
|
||||
const data = await this.api.guilds(id).preview.get();
|
||||
return new GuildPreview(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a link that can be used to invite the bot to a guild.
|
||||
* @param {PermissionResolvable} [permissions] Permissions to request
|
||||
* @returns {Promise<string>}
|
||||
* @example
|
||||
* client.generateInvite(['SEND_MESSAGES', 'MANAGE_GUILD', 'MENTION_EVERYONE'])
|
||||
* .then(link => console.log(`Generated bot invite link: ${link}`))
|
||||
* .catch(console.error);
|
||||
* Obtains the widget data of a guild from Discord, available for guilds with the widget enabled.
|
||||
* @param {GuildResolvable} guild The guild to fetch the widget data for
|
||||
* @returns {Promise<Widget>}
|
||||
*/
|
||||
async generateInvite(permissions) {
|
||||
permissions = Permissions.resolve(permissions);
|
||||
const application = await this.fetchApplication();
|
||||
async fetchGuildWidget(guild) {
|
||||
const id = this.guilds.resolveId(guild);
|
||||
if (!id) throw new TypeError('INVALID_TYPE', 'guild', 'GuildResolvable');
|
||||
const data = await this.api.guilds(id, 'widget.json').get();
|
||||
return new Widget(this, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for {@link Client#generateInvite}.
|
||||
* @typedef {Object} InviteGenerationOptions
|
||||
* @property {InviteScope[]} scopes Scopes that should be requested
|
||||
* @property {PermissionResolvable} [permissions] Permissions to request
|
||||
* @property {GuildResolvable} [guild] Guild to preselect
|
||||
* @property {boolean} [disableGuildSelect] Whether to disable the guild selection
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generates a link that can be used to invite the bot to a guild.
|
||||
* @param {InviteGenerationOptions} [options={}] Options for the invite
|
||||
* @returns {string}
|
||||
* @example
|
||||
* const link = client.generateInvite({
|
||||
* scopes: ['applications.commands'],
|
||||
* });
|
||||
* console.log(`Generated application invite link: ${link}`);
|
||||
* @example
|
||||
* const link = client.generateInvite({
|
||||
* permissions: [
|
||||
* Permissions.FLAGS.SEND_MESSAGES,
|
||||
* Permissions.FLAGS.MANAGE_GUILD,
|
||||
* Permissions.FLAGS.MENTION_EVERYONE,
|
||||
* ],
|
||||
* scopes: ['bot'],
|
||||
* });
|
||||
* console.log(`Generated bot invite link: ${link}`);
|
||||
*/
|
||||
generateInvite(options = {}) {
|
||||
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
|
||||
if (!this.application) throw new Error('CLIENT_NOT_READY', 'generate an invite link');
|
||||
|
||||
const query = new URLSearchParams({
|
||||
client_id: application.id,
|
||||
permissions: permissions,
|
||||
scope: 'bot',
|
||||
client_id: this.application.id,
|
||||
});
|
||||
|
||||
const { scopes } = options;
|
||||
if (typeof scopes === 'undefined') {
|
||||
throw new TypeError('INVITE_MISSING_SCOPES');
|
||||
}
|
||||
if (!Array.isArray(scopes)) {
|
||||
throw new TypeError('INVALID_TYPE', 'scopes', 'Array of Invite Scopes', true);
|
||||
}
|
||||
if (!scopes.some(scope => ['bot', 'applications.commands'].includes(scope))) {
|
||||
throw new TypeError('INVITE_MISSING_SCOPES');
|
||||
}
|
||||
const invalidScope = scopes.find(scope => !InviteScopes.includes(scope));
|
||||
if (invalidScope) {
|
||||
throw new TypeError('INVALID_ELEMENT', 'Array', 'scopes', invalidScope);
|
||||
}
|
||||
query.set('scope', scopes.join(' '));
|
||||
|
||||
if (options.permissions) {
|
||||
const permissions = Permissions.resolve(options.permissions);
|
||||
if (permissions) query.set('permissions', permissions);
|
||||
}
|
||||
|
||||
if (options.disableGuildSelect) {
|
||||
query.set('disable_guild_select', true);
|
||||
}
|
||||
|
||||
if (options.guild) {
|
||||
const guildId = this.guilds.resolveId(options.guild);
|
||||
if (!guildId) throw new TypeError('INVALID_TYPE', 'options.guild', 'GuildResolvable');
|
||||
query.set('guild_id', guildId);
|
||||
}
|
||||
|
||||
return `${this.options.http.api}${this.api.oauth2.authorize}?${query}`;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return super.toJSON({
|
||||
readyAt: false,
|
||||
presences: false,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -382,8 +540,10 @@ class Client extends BaseClient {
|
||||
* @private
|
||||
*/
|
||||
_validateOptions(options = this.options) {
|
||||
if (typeof options.ws.intents !== 'undefined') {
|
||||
options.ws.intents = Intents.resolve(options.ws.intents);
|
||||
if (typeof options.intents === 'undefined') {
|
||||
throw new TypeError('CLIENT_MISSING_INTENTS');
|
||||
} else {
|
||||
options.intents = Intents.resolve(options.intents);
|
||||
}
|
||||
if (typeof options.shardCount !== 'number' || isNaN(options.shardCount) || options.shardCount < 1) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'shardCount', 'a number greater than or equal to 1');
|
||||
@@ -392,8 +552,8 @@ class Client extends BaseClient {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'shards', "'auto', a number or array of numbers");
|
||||
}
|
||||
if (options.shards && !options.shards.length) throw new RangeError('CLIENT_INVALID_PROVIDED_SHARDS');
|
||||
if (typeof options.messageCacheMaxSize !== 'number' || isNaN(options.messageCacheMaxSize)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'messageCacheMaxSize', 'a number');
|
||||
if (typeof options.makeCache !== 'function') {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'makeCache', 'a function');
|
||||
}
|
||||
if (typeof options.messageCacheLifetime !== 'number' || isNaN(options.messageCacheLifetime)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'The messageCacheLifetime', 'a number');
|
||||
@@ -401,11 +561,8 @@ class Client extends BaseClient {
|
||||
if (typeof options.messageSweepInterval !== 'number' || isNaN(options.messageSweepInterval)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'messageSweepInterval', 'a number');
|
||||
}
|
||||
if (typeof options.fetchAllMembers !== 'boolean') {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'fetchAllMembers', 'a boolean');
|
||||
}
|
||||
if (typeof options.disableMentions !== 'string') {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'disableMentions', 'a string');
|
||||
if (typeof options.invalidRequestWarningInterval !== 'number' || isNaN(options.invalidRequestWarningInterval)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'invalidRequestWarningInterval', 'a number');
|
||||
}
|
||||
if (!Array.isArray(options.partials)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'partials', 'an Array');
|
||||
@@ -416,12 +573,27 @@ class Client extends BaseClient {
|
||||
if (typeof options.restRequestTimeout !== 'number' || isNaN(options.restRequestTimeout)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'restRequestTimeout', 'a number');
|
||||
}
|
||||
if (typeof options.restGlobalRateLimit !== 'number' || isNaN(options.restGlobalRateLimit)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'restGlobalRateLimit', 'a number');
|
||||
}
|
||||
if (typeof options.restSweepInterval !== 'number' || isNaN(options.restSweepInterval)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'restSweepInterval', 'a number');
|
||||
}
|
||||
if (typeof options.retryLimit !== 'number' || isNaN(options.retryLimit)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'retryLimit', 'a number');
|
||||
}
|
||||
if (typeof options.failIfNotExists !== 'boolean') {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'failIfNotExists', 'a boolean');
|
||||
}
|
||||
if (!Array.isArray(options.userAgentSuffix)) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'userAgentSuffix', 'an array of strings');
|
||||
}
|
||||
if (
|
||||
typeof options.rejectOnRateLimit !== 'undefined' &&
|
||||
!(typeof options.rejectOnRateLimit === 'function' || Array.isArray(options.rejectOnRateLimit))
|
||||
) {
|
||||
throw new TypeError('CLIENT_INVALID_OPTION', 'rejectOnRateLimit', 'an array or a function');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,3 +610,8 @@ module.exports = Client;
|
||||
* @event Client#debug
|
||||
* @param {string} info The debug information
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external Collection
|
||||
* @see {@link https://discord.js.org/#/docs/collection/main/class/Collection}
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const BaseClient = require('./BaseClient');
|
||||
const { Error } = require('../errors');
|
||||
const Webhook = require('../structures/Webhook');
|
||||
|
||||
/**
|
||||
@@ -10,20 +11,49 @@ const Webhook = require('../structures/Webhook');
|
||||
*/
|
||||
class WebhookClient extends BaseClient {
|
||||
/**
|
||||
* @param {Snowflake} id ID of the webhook
|
||||
* @param {string} token Token of the webhook
|
||||
* @param {ClientOptions} [options] Options for the client
|
||||
* @example
|
||||
* // Create a new webhook and send a message
|
||||
* const hook = new Discord.WebhookClient('1234', 'abcdef');
|
||||
* hook.send('This will send a message').catch(console.error);
|
||||
* The data for the webhook client containing either an id and token or just a URL
|
||||
* @typedef {Object} WebhookClientData
|
||||
* @property {Snowflake} [id] The id of the webhook
|
||||
* @property {string} [token] The token of the webhook
|
||||
* @property {string} [url] The full url for the webhook client
|
||||
*/
|
||||
constructor(id, token, options) {
|
||||
|
||||
/**
|
||||
* @param {WebhookClientData} data The data of the webhook
|
||||
* @param {ClientOptions} [options] Options for the client
|
||||
*/
|
||||
constructor(data, options) {
|
||||
super(options);
|
||||
Object.defineProperty(this, 'client', { value: this });
|
||||
let { id, token } = data;
|
||||
|
||||
if ('url' in data) {
|
||||
const url = data.url.match(
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
/^https?:\/\/(?:canary|ptb)?\.?discord\.com\/api\/webhooks(?:\/v[0-9]\d*)?\/([^\/]+)\/([^\/]+)/i,
|
||||
);
|
||||
|
||||
if (!url || url.length <= 1) throw new Error('WEBHOOK_URL_INVALID');
|
||||
|
||||
[, id, token] = url;
|
||||
}
|
||||
|
||||
this.id = id;
|
||||
Object.defineProperty(this, 'token', { value: token, writable: true, configurable: true });
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by Webhook
|
||||
/* eslint-disable no-empty-function */
|
||||
send() {}
|
||||
sendSlackMessage() {}
|
||||
fetchMessage() {}
|
||||
edit() {}
|
||||
editMessage() {}
|
||||
delete() {}
|
||||
deleteMessage() {}
|
||||
get createdTimestamp() {}
|
||||
get createdAt() {}
|
||||
get url() {}
|
||||
}
|
||||
|
||||
Webhook.applyToClass(WebhookClient);
|
||||
|
||||
@@ -26,20 +26,20 @@ class GenericAction {
|
||||
getPayload(data, manager, id, partialType, cache) {
|
||||
const existing = manager.cache.get(id);
|
||||
if (!existing && this.client.options.partials.includes(partialType)) {
|
||||
return manager.add(data, cache);
|
||||
return manager._add(data, cache);
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
|
||||
getChannel(data) {
|
||||
const id = data.channel_id || data.id;
|
||||
const id = data.channel_id ?? data.id;
|
||||
return (
|
||||
data.channel ||
|
||||
data.channel ??
|
||||
this.getPayload(
|
||||
{
|
||||
id,
|
||||
guild_id: data.guild_id,
|
||||
recipients: [data.author || { id: data.user_id }],
|
||||
recipients: [data.author ?? data.user ?? { id: data.user_id }],
|
||||
},
|
||||
this.client.channels,
|
||||
id,
|
||||
@@ -49,14 +49,14 @@ class GenericAction {
|
||||
}
|
||||
|
||||
getMessage(data, channel, cache) {
|
||||
const id = data.message_id || data.id;
|
||||
const id = data.message_id ?? data.id;
|
||||
return (
|
||||
data.message ||
|
||||
data.message ??
|
||||
this.getPayload(
|
||||
{
|
||||
id,
|
||||
channel_id: channel.id,
|
||||
guild_id: data.guild_id || (channel.guild ? channel.guild.id : null),
|
||||
guild_id: data.guild_id ?? channel.guild?.id,
|
||||
},
|
||||
channel.messages,
|
||||
id,
|
||||
@@ -67,12 +67,12 @@ class GenericAction {
|
||||
}
|
||||
|
||||
getReaction(data, message, user) {
|
||||
const id = data.emoji.id || decodeURIComponent(data.emoji.name);
|
||||
const id = data.emoji.id ?? decodeURIComponent(data.emoji.name);
|
||||
return this.getPayload(
|
||||
{
|
||||
emoji: data.emoji,
|
||||
count: message.partial ? null : 0,
|
||||
me: user ? user.id === this.client.user.id : false,
|
||||
me: user?.id === this.client.user.id,
|
||||
},
|
||||
message.reactions,
|
||||
id,
|
||||
@@ -81,22 +81,24 @@ class GenericAction {
|
||||
}
|
||||
|
||||
getMember(data, guild) {
|
||||
const id = data.user.id;
|
||||
return this.getPayload(
|
||||
{
|
||||
user: {
|
||||
id,
|
||||
},
|
||||
},
|
||||
guild.members,
|
||||
id,
|
||||
PartialTypes.GUILD_MEMBER,
|
||||
);
|
||||
return this.getPayload(data, guild.members, data.user.id, PartialTypes.GUILD_MEMBER);
|
||||
}
|
||||
|
||||
getUser(data) {
|
||||
const id = data.user_id;
|
||||
return data.user || this.getPayload({ id }, this.client.users, id, PartialTypes.USER);
|
||||
return data.user ?? this.getPayload({ id }, this.client.users, id, PartialTypes.USER);
|
||||
}
|
||||
|
||||
getUserFromMember(data) {
|
||||
if (data.guild_id && data.member?.user) {
|
||||
const guild = this.client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
return guild.members._add(data.member).user;
|
||||
} else {
|
||||
return this.client.users._add(data.member.user);
|
||||
}
|
||||
}
|
||||
return this.getUser(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +1,17 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
class ActionsManager {
|
||||
constructor(client) {
|
||||
this.client = client;
|
||||
|
||||
this.register(require('./MessageCreate'));
|
||||
this.register(require('./MessageDelete'));
|
||||
this.register(require('./MessageDeleteBulk'));
|
||||
this.register(require('./MessageUpdate'));
|
||||
this.register(require('./MessageReactionAdd'));
|
||||
this.register(require('./MessageReactionRemove'));
|
||||
this.register(require('./MessageReactionRemoveAll'));
|
||||
this.register(require('./MessageReactionRemoveEmoji'));
|
||||
this.register(require('./ChannelCreate'));
|
||||
this.register(require('./ChannelDelete'));
|
||||
this.register(require('./ChannelUpdate'));
|
||||
this.register(require('./GuildDelete'));
|
||||
this.register(require('./GuildUpdate'));
|
||||
this.register(require('./InviteCreate'));
|
||||
this.register(require('./InviteDelete'));
|
||||
this.register(require('./GuildMemberRemove'));
|
||||
this.register(require('./GuildBanRemove'));
|
||||
this.register(require('./GuildRoleCreate'));
|
||||
this.register(require('./GuildRoleDelete'));
|
||||
this.register(require('./GuildRoleUpdate'));
|
||||
this.register(require('./PresenceUpdate'));
|
||||
this.register(require('./UserUpdate'));
|
||||
this.register(require('./VoiceStateUpdate'));
|
||||
this.register(require('./GuildEmojiCreate'));
|
||||
this.register(require('./GuildEmojiDelete'));
|
||||
this.register(require('./GuildEmojiUpdate'));
|
||||
this.register(require('./GuildEmojisUpdate'));
|
||||
this.register(require('./GuildRolesPositionUpdate'));
|
||||
this.register(require('./GuildChannelsPositionUpdate'));
|
||||
this.register(require('./GuildIntegrationsUpdate'));
|
||||
this.register(require('./WebhooksUpdate'));
|
||||
const files = fs.readdirSync(__dirname);
|
||||
|
||||
for (const file of files) {
|
||||
if (['Action.js', 'ActionsManager.js'].includes(file)) continue;
|
||||
this.register(require(`./${file}`));
|
||||
}
|
||||
}
|
||||
|
||||
register(Action) {
|
||||
|
||||
@@ -7,12 +7,12 @@ class ChannelCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const existing = client.channels.cache.has(data.id);
|
||||
const channel = client.channels.add(data);
|
||||
const channel = client.channels._add(data);
|
||||
if (!existing && channel) {
|
||||
/**
|
||||
* Emitted whenever a channel is created.
|
||||
* Emitted whenever a guild channel is created.
|
||||
* @event Client#channelCreate
|
||||
* @param {DMChannel|GuildChannel} channel The channel that was created
|
||||
* @param {GuildChannel} channel The channel that was created
|
||||
*/
|
||||
client.emit(Events.CHANNEL_CREATE, channel);
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ class ChannelDeleteAction extends Action {
|
||||
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
let channel = client.channels.cache.get(data.id);
|
||||
const channel = client.channels.cache.get(data.id);
|
||||
|
||||
if (channel) {
|
||||
client.channels.remove(channel.id);
|
||||
client.channels._remove(channel.id);
|
||||
channel.deleted = true;
|
||||
if (channel.messages && !(channel instanceof DMChannel)) {
|
||||
for (const message of channel.messages.cache.values()) {
|
||||
|
||||
@@ -12,10 +12,9 @@ class ChannelUpdateAction extends Action {
|
||||
if (channel) {
|
||||
const old = channel._update(data);
|
||||
|
||||
if (ChannelTypes[channel.type.toUpperCase()] !== data.type) {
|
||||
if (ChannelTypes[channel.type] !== data.type) {
|
||||
const newChannel = Channel.create(this.client, data, channel.guild);
|
||||
for (const [id, message] of channel.messages.cache) newChannel.messages.cache.set(id, message);
|
||||
newChannel._typing = new Map(channel._typing);
|
||||
channel = newChannel;
|
||||
this.client.channels.cache.set(channel.id, channel);
|
||||
}
|
||||
@@ -24,6 +23,8 @@ class ChannelUpdateAction extends Action {
|
||||
old,
|
||||
updated: channel,
|
||||
};
|
||||
} else {
|
||||
client.channels._add(data);
|
||||
}
|
||||
|
||||
return {};
|
||||
|
||||
20
src/client/actions/GuildBanAdd.js
Normal file
20
src/client/actions/GuildBanAdd.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class GuildBanAdd extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
|
||||
/**
|
||||
* Emitted whenever a member is banned from a guild.
|
||||
* @event Client#guildBanAdd
|
||||
* @param {GuildBan} ban The ban that occurred
|
||||
*/
|
||||
if (guild) client.emit(Events.GUILD_BAN_ADD, guild.bans._add(data));
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildBanAdd;
|
||||
@@ -1,20 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const GuildBan = require('../../structures/GuildBan');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class GuildBanRemove extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
const user = client.users.add(data.user);
|
||||
|
||||
/**
|
||||
* Emitted whenever a member is unbanned from a guild.
|
||||
* @event Client#guildBanRemove
|
||||
* @param {Guild} guild The guild that the unban occurred in
|
||||
* @param {User} user The user that was unbanned
|
||||
* @param {GuildBan} ban The ban that was removed
|
||||
*/
|
||||
if (guild && user) client.emit(Events.GUILD_BAN_REMOVE, guild, user);
|
||||
if (guild) {
|
||||
const ban = guild.bans.cache.get(data.user.id) ?? new GuildBan(client, data, guild);
|
||||
guild.bans.cache.delete(ban.user.id);
|
||||
client.emit(Events.GUILD_BAN_REMOVE, ban);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,7 @@ class GuildDeleteAction extends Action {
|
||||
|
||||
let guild = client.guilds.cache.get(data.id);
|
||||
if (guild) {
|
||||
for (const channel of guild.channels.cache.values()) {
|
||||
if (channel.type === 'text') channel.stopTyping(true);
|
||||
}
|
||||
|
||||
if (guild.available && data.unavailable) {
|
||||
if (data.unavailable) {
|
||||
// Guild is unavailable
|
||||
guild.available = false;
|
||||
|
||||
@@ -36,8 +32,8 @@ class GuildDeleteAction extends Action {
|
||||
};
|
||||
}
|
||||
|
||||
for (const channel of guild.channels.cache.values()) this.client.channels.remove(channel.id);
|
||||
if (guild.voice && guild.voice.connection) guild.voice.connection.disconnect();
|
||||
for (const channel of guild.channels.cache.values()) this.client.channels._remove(channel.id);
|
||||
client.voice.adapters.get(data.id)?.destroy();
|
||||
|
||||
// Delete guild
|
||||
client.guilds.cache.delete(guild.id);
|
||||
@@ -53,14 +49,14 @@ class GuildDeleteAction extends Action {
|
||||
this.deleted.set(guild.id, guild);
|
||||
this.scheduleForDeletion(guild.id);
|
||||
} else {
|
||||
guild = this.deleted.get(data.id) || null;
|
||||
guild = this.deleted.get(data.id) ?? null;
|
||||
}
|
||||
|
||||
return { guild };
|
||||
}
|
||||
|
||||
scheduleForDeletion(id) {
|
||||
this.client.setTimeout(() => this.deleted.delete(id), this.client.options.restWsBridgeTimeout);
|
||||
setTimeout(() => this.deleted.delete(id), this.client.options.restWsBridgeTimeout).unref();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,14 @@ const { Events } = require('../../util/Constants');
|
||||
|
||||
class GuildEmojiCreateAction extends Action {
|
||||
handle(guild, createdEmoji) {
|
||||
const emoji = guild.emojis.add(createdEmoji);
|
||||
const already = guild.emojis.cache.has(createdEmoji.id);
|
||||
const emoji = guild.emojis._add(createdEmoji);
|
||||
/**
|
||||
* Emitted whenever a custom emoji is created in a guild.
|
||||
* @event Client#emojiCreate
|
||||
* @param {GuildEmoji} emoji The emoji that was created
|
||||
*/
|
||||
this.client.emit(Events.GUILD_EMOJI_CREATE, emoji);
|
||||
if (!already) this.client.emit(Events.GUILD_EMOJI_CREATE, emoji);
|
||||
return { emoji };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ const Action = require('./Action');
|
||||
class GuildEmojisUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const guild = this.client.guilds.cache.get(data.guild_id);
|
||||
if (!guild || !guild.emojis) return;
|
||||
if (!guild?.emojis) return;
|
||||
|
||||
const deletions = new Map(guild.emojis.cache);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class GuildMemberRemoveAction extends Action {
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
let member = null;
|
||||
if (guild) {
|
||||
member = this.getMember(data, guild);
|
||||
member = this.getMember({ user: data.user }, guild);
|
||||
guild.memberCount--;
|
||||
if (member) {
|
||||
member.deleted = true;
|
||||
|
||||
44
src/client/actions/GuildMemberUpdate.js
Normal file
44
src/client/actions/GuildMemberUpdate.js
Normal file
@@ -0,0 +1,44 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Status, Events } = require('../../util/Constants');
|
||||
|
||||
class GuildMemberUpdateAction extends Action {
|
||||
handle(data, shard) {
|
||||
const { client } = this;
|
||||
if (data.user.username) {
|
||||
const user = client.users.cache.get(data.user.id);
|
||||
if (!user) {
|
||||
client.users._add(data.user);
|
||||
} else if (!user.equals(data.user)) {
|
||||
client.actions.UserUpdate.handle(data.user);
|
||||
}
|
||||
}
|
||||
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
const member = this.getMember({ user: data.user }, guild);
|
||||
if (member) {
|
||||
const old = member._update(data);
|
||||
/**
|
||||
* Emitted whenever a guild member changes - i.e. new role, removed role, nickname.
|
||||
* Also emitted when the user's details (e.g. username) change.
|
||||
* @event Client#guildMemberUpdate
|
||||
* @param {GuildMember} oldMember The member before the update
|
||||
* @param {GuildMember} newMember The member after the update
|
||||
*/
|
||||
if (shard.status === Status.READY && !member.equals(old)) client.emit(Events.GUILD_MEMBER_UPDATE, old, member);
|
||||
} else {
|
||||
const newMember = guild.members._add(data);
|
||||
/**
|
||||
* Emitted whenever a member becomes available in a large guild.
|
||||
* @event Client#guildMemberAvailable
|
||||
* @param {GuildMember} member The member that became available
|
||||
*/
|
||||
this.client.emit(Events.GUILD_MEMBER_AVAILABLE, newMember);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildMemberUpdateAction;
|
||||
@@ -10,7 +10,7 @@ class GuildRoleCreate extends Action {
|
||||
let role;
|
||||
if (guild) {
|
||||
const already = guild.roles.cache.has(data.role.id);
|
||||
role = guild.roles.add(data.role);
|
||||
role = guild.roles._add(data.role);
|
||||
/**
|
||||
* Emitted whenever a role is created.
|
||||
* @event Client#roleCreate
|
||||
|
||||
20
src/client/actions/GuildStickerCreate.js
Normal file
20
src/client/actions/GuildStickerCreate.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class GuildStickerCreateAction extends Action {
|
||||
handle(guild, createdSticker) {
|
||||
const already = guild.stickers.cache.has(createdSticker.id);
|
||||
const sticker = guild.stickers._add(createdSticker);
|
||||
/**
|
||||
* Emitted whenever a custom sticker is created in a guild.
|
||||
* @event Client#stickerCreate
|
||||
* @param {Sticker} sticker The sticker that was created
|
||||
*/
|
||||
if (!already) this.client.emit(Events.GUILD_STICKER_CREATE, sticker);
|
||||
return { sticker };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildStickerCreateAction;
|
||||
20
src/client/actions/GuildStickerDelete.js
Normal file
20
src/client/actions/GuildStickerDelete.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class GuildStickerDeleteAction extends Action {
|
||||
handle(sticker) {
|
||||
sticker.guild.stickers.cache.delete(sticker.id);
|
||||
sticker.deleted = true;
|
||||
/**
|
||||
* Emitted whenever a custom sticker is deleted in a guild.
|
||||
* @event Client#stickerDelete
|
||||
* @param {Sticker} sticker The sticker that was deleted
|
||||
*/
|
||||
this.client.emit(Events.GUILD_STICKER_DELETE, sticker);
|
||||
return { sticker };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildStickerDeleteAction;
|
||||
20
src/client/actions/GuildStickerUpdate.js
Normal file
20
src/client/actions/GuildStickerUpdate.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class GuildStickerUpdateAction extends Action {
|
||||
handle(current, data) {
|
||||
const old = current._update(data);
|
||||
/**
|
||||
* Emitted whenever a custom sticker is updated in a guild.
|
||||
* @event Client#stickerUpdate
|
||||
* @param {Sticker} oldSticker The old sticker
|
||||
* @param {Sticker} newSticker The new sticker
|
||||
*/
|
||||
this.client.emit(Events.GUILD_STICKER_UPDATE, old, current);
|
||||
return { sticker: current };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildStickerUpdateAction;
|
||||
34
src/client/actions/GuildStickersUpdate.js
Normal file
34
src/client/actions/GuildStickersUpdate.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
|
||||
class GuildStickersUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const guild = this.client.guilds.cache.get(data.guild_id);
|
||||
if (!guild?.stickers) return;
|
||||
|
||||
const deletions = new Map(guild.stickers.cache);
|
||||
|
||||
for (const sticker of data.stickers) {
|
||||
// Determine type of sticker event
|
||||
const cachedSticker = guild.stickers.cache.get(sticker.id);
|
||||
if (cachedSticker) {
|
||||
deletions.delete(sticker.id);
|
||||
if (!cachedSticker.equals(sticker)) {
|
||||
// Sticker updated
|
||||
this.client.actions.GuildStickerUpdate.handle(cachedSticker, sticker);
|
||||
}
|
||||
} else {
|
||||
// Sticker added
|
||||
this.client.actions.GuildStickerCreate.handle(guild, sticker);
|
||||
}
|
||||
}
|
||||
|
||||
for (const sticker of deletions.values()) {
|
||||
// Sticker deleted
|
||||
this.client.actions.GuildStickerDelete.handle(sticker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GuildStickersUpdateAction;
|
||||
81
src/client/actions/InteractionCreate.js
Normal file
81
src/client/actions/InteractionCreate.js
Normal file
@@ -0,0 +1,81 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const ButtonInteraction = require('../../structures/ButtonInteraction');
|
||||
const CommandInteraction = require('../../structures/CommandInteraction');
|
||||
const ContextMenuInteraction = require('../../structures/ContextMenuInteraction');
|
||||
const SelectMenuInteraction = require('../../structures/SelectMenuInteraction');
|
||||
const { Events, InteractionTypes, MessageComponentTypes, ApplicationCommandTypes } = require('../../util/Constants');
|
||||
|
||||
let deprecationEmitted = false;
|
||||
|
||||
class InteractionCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
// Resolve and cache partial channels for Interaction#channel getter
|
||||
this.getChannel(data);
|
||||
|
||||
let InteractionType;
|
||||
switch (data.type) {
|
||||
case InteractionTypes.APPLICATION_COMMAND:
|
||||
switch (data.data.type) {
|
||||
case ApplicationCommandTypes.CHAT_INPUT:
|
||||
InteractionType = CommandInteraction;
|
||||
break;
|
||||
case ApplicationCommandTypes.USER:
|
||||
case ApplicationCommandTypes.MESSAGE:
|
||||
InteractionType = ContextMenuInteraction;
|
||||
break;
|
||||
default:
|
||||
client.emit(
|
||||
Events.DEBUG,
|
||||
`[INTERACTION] Received application command interaction with unknown type: ${data.data.type}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case InteractionTypes.MESSAGE_COMPONENT:
|
||||
switch (data.data.component_type) {
|
||||
case MessageComponentTypes.BUTTON:
|
||||
InteractionType = ButtonInteraction;
|
||||
break;
|
||||
case MessageComponentTypes.SELECT_MENU:
|
||||
InteractionType = SelectMenuInteraction;
|
||||
break;
|
||||
default:
|
||||
client.emit(
|
||||
Events.DEBUG,
|
||||
`[INTERACTION] Received component interaction with unknown type: ${data.data.component_type}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
client.emit(Events.DEBUG, `[INTERACTION] Received interaction with unknown type: ${data.type}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const interaction = new InteractionType(client, data);
|
||||
|
||||
/**
|
||||
* Emitted when an interaction is created.
|
||||
* @event Client#interactionCreate
|
||||
* @param {Interaction} interaction The interaction which was created
|
||||
*/
|
||||
client.emit(Events.INTERACTION_CREATE, interaction);
|
||||
|
||||
/**
|
||||
* Emitted when an interaction is created.
|
||||
* @event Client#interaction
|
||||
* @param {Interaction} interaction The interaction which was created
|
||||
* @deprecated Use {@link Client#interactionCreate} instead
|
||||
*/
|
||||
if (client.emit('interaction', interaction) && !deprecationEmitted) {
|
||||
deprecationEmitted = true;
|
||||
process.emitWarning('The interaction event is deprecated. Use interactionCreate instead', 'DeprecationWarning');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InteractionCreateAction;
|
||||
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Invite = require('../../structures/Invite');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class InviteCreateAction extends Action {
|
||||
@@ -9,14 +8,15 @@ class InviteCreateAction extends Action {
|
||||
const client = this.client;
|
||||
const channel = client.channels.cache.get(data.channel_id);
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!channel && !guild) return false;
|
||||
if (!channel) return false;
|
||||
|
||||
const inviteData = Object.assign(data, { channel, guild });
|
||||
const invite = new Invite(client, inviteData);
|
||||
const invite = guild.invites._add(inviteData);
|
||||
|
||||
/**
|
||||
* Emitted when an invite is created.
|
||||
* <info> This event only triggers if the client has `MANAGE_GUILD` permissions for the guild,
|
||||
* or `MANAGE_CHANNEL` permissions for the channel.</info>
|
||||
* or `MANAGE_CHANNELS` permissions for the channel.</info>
|
||||
* @event Client#inviteCreate
|
||||
* @param {Invite} invite The invite that was created
|
||||
*/
|
||||
|
||||
@@ -9,15 +9,16 @@ class InviteDeleteAction extends Action {
|
||||
const client = this.client;
|
||||
const channel = client.channels.cache.get(data.channel_id);
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!channel && !guild) return false;
|
||||
if (!channel) return false;
|
||||
|
||||
const inviteData = Object.assign(data, { channel, guild });
|
||||
const invite = new Invite(client, inviteData);
|
||||
guild.invites.cache.delete(invite.code);
|
||||
|
||||
/**
|
||||
* Emitted when an invite is deleted.
|
||||
* <info> This event only triggers if the client has `MANAGE_GUILD` permissions for the guild,
|
||||
* or `MANAGE_CHANNEL` permissions for the channel.</info>
|
||||
* or `MANAGE_CHANNELS` permissions for the channel.</info>
|
||||
* @event Client#inviteDelete
|
||||
* @param {Invite} invite The invite that was deleted
|
||||
*/
|
||||
|
||||
@@ -3,32 +3,36 @@
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
let deprecationEmitted = false;
|
||||
|
||||
class MessageCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = client.channels.cache.get(data.channel_id);
|
||||
const channel = this.getChannel(data);
|
||||
if (channel) {
|
||||
const existing = channel.messages.cache.get(data.id);
|
||||
if (existing) return { message: existing };
|
||||
const message = channel.messages.add(data);
|
||||
const user = message.author;
|
||||
let member = message.member;
|
||||
channel.lastMessageID = data.id;
|
||||
if (user) {
|
||||
user.lastMessageID = data.id;
|
||||
user.lastMessageChannelID = channel.id;
|
||||
}
|
||||
if (member) {
|
||||
member.lastMessageID = data.id;
|
||||
member.lastMessageChannelID = channel.id;
|
||||
}
|
||||
const message = channel.messages._add(data);
|
||||
channel.lastMessageId = data.id;
|
||||
|
||||
/**
|
||||
* Emitted whenever a message is created.
|
||||
* @event Client#messageCreate
|
||||
* @param {Message} message The created message
|
||||
*/
|
||||
client.emit(Events.MESSAGE_CREATE, message);
|
||||
|
||||
/**
|
||||
* Emitted whenever a message is created.
|
||||
* @event Client#message
|
||||
* @param {Message} message The created message
|
||||
* @deprecated Use {@link Client#messageCreate} instead
|
||||
*/
|
||||
client.emit(Events.MESSAGE_CREATE, message);
|
||||
if (client.emit('message', message) && !deprecationEmitted) {
|
||||
deprecationEmitted = true;
|
||||
process.emitWarning('The message event is deprecated. Use messageCreate instead', 'DeprecationWarning');
|
||||
}
|
||||
|
||||
return { message };
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const Action = require('./Action');
|
||||
const Collection = require('../../util/Collection');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class MessageDeleteBulkAction extends Action {
|
||||
@@ -31,7 +31,7 @@ class MessageDeleteBulkAction extends Action {
|
||||
/**
|
||||
* Emitted whenever messages are deleted in bulk.
|
||||
* @event Client#messageDeleteBulk
|
||||
* @param {Collection<Snowflake, Message>} messages The deleted messages, mapped by their ID
|
||||
* @param {Collection<Snowflake, Message>} messages The deleted messages, mapped by their id
|
||||
*/
|
||||
if (messages.size > 0) client.emit(Events.MESSAGE_BULK_DELETE, messages);
|
||||
return { messages };
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
|
||||
const { PartialTypes } = require('../../util/Constants');
|
||||
|
||||
/*
|
||||
{ user_id: 'id',
|
||||
message_id: 'id',
|
||||
emoji: { name: '<27>', id: null },
|
||||
channel_id: 'id' } }
|
||||
channel_id: 'id',
|
||||
// If originating from a guild
|
||||
guild_id: 'id',
|
||||
member: { ..., user: { ... } } }
|
||||
*/
|
||||
|
||||
class MessageReactionAdd extends Action {
|
||||
handle(data) {
|
||||
if (!data.emoji) return false;
|
||||
|
||||
const user = this.getUser(data);
|
||||
const user = this.getUserFromMember(data);
|
||||
if (!user) return false;
|
||||
|
||||
// Verify channel
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel || channel.type === 'voice') return false;
|
||||
if (!channel || VoiceBasedChannelTypes.includes(channel.type)) return false;
|
||||
|
||||
// Verify message
|
||||
const message = this.getMessage(data, channel);
|
||||
@@ -28,7 +31,9 @@ class MessageReactionAdd extends Action {
|
||||
|
||||
// Verify reaction
|
||||
if (message.partial && !this.client.options.partials.includes(PartialTypes.REACTION)) return false;
|
||||
const reaction = message.reactions.add({
|
||||
const existing = message.reactions.cache.get(data.emoji.id ?? data.emoji.name);
|
||||
if (existing?.users.cache.has(user.id)) return { message, reaction: existing, user };
|
||||
const reaction = message.reactions._add({
|
||||
emoji: data.emoji,
|
||||
count: message.partial ? null : 0,
|
||||
me: user.id === this.client.user.id,
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
|
||||
|
||||
/*
|
||||
{ user_id: 'id',
|
||||
message_id: 'id',
|
||||
emoji: { name: '<27>', id: null },
|
||||
channel_id: 'id' } }
|
||||
channel_id: 'id',
|
||||
guild_id: 'id' }
|
||||
*/
|
||||
|
||||
class MessageReactionRemove extends Action {
|
||||
@@ -19,7 +20,7 @@ class MessageReactionRemove extends Action {
|
||||
|
||||
// Verify channel
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel || channel.type === 'voice') return false;
|
||||
if (!channel || VoiceBasedChannelTypes.includes(channel.type)) return false;
|
||||
|
||||
// Verify message
|
||||
const message = this.getMessage(data, channel);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
|
||||
|
||||
class MessageReactionRemoveAll extends Action {
|
||||
handle(data) {
|
||||
// Verify channel
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel || channel.type === 'voice') return false;
|
||||
if (!channel || VoiceBasedChannelTypes.includes(channel.type)) return false;
|
||||
|
||||
// Verify message
|
||||
const message = this.getMessage(data, channel);
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
const { Events, VoiceBasedChannelTypes } = require('../../util/Constants');
|
||||
|
||||
class MessageReactionRemoveEmoji extends Action {
|
||||
handle(data) {
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel || channel.type === 'voice') return false;
|
||||
if (!channel || VoiceBasedChannelTypes.includes(channel.type)) return false;
|
||||
|
||||
const message = this.getMessage(data, channel);
|
||||
if (!message) return false;
|
||||
|
||||
const reaction = this.getReaction(data, message);
|
||||
if (!reaction) return false;
|
||||
if (!message.partial) message.reactions.cache.delete(reaction.emoji.id || reaction.emoji.name);
|
||||
if (!message.partial) message.reactions.cache.delete(reaction.emoji.id ?? reaction.emoji.name);
|
||||
|
||||
/**
|
||||
* Emitted when a bot removes an emoji reaction from a cached message.
|
||||
|
||||
@@ -9,9 +9,9 @@ class MessageUpdateAction extends Action {
|
||||
const { id, channel_id, guild_id, author, timestamp, type } = data;
|
||||
const message = this.getMessage({ id, channel_id, guild_id, author, timestamp, type }, channel);
|
||||
if (message) {
|
||||
message.patch(data);
|
||||
const old = message._update(data, true);
|
||||
return {
|
||||
old: message._edits[0],
|
||||
old,
|
||||
updated: message,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,37 +6,35 @@ const { Events } = require('../../util/Constants');
|
||||
class PresenceUpdateAction extends Action {
|
||||
handle(data) {
|
||||
let user = this.client.users.cache.get(data.user.id);
|
||||
if (!user && data.user.username) user = this.client.users.add(data.user);
|
||||
if (!user && data.user?.username) user = this.client.users._add(data.user);
|
||||
if (!user) return;
|
||||
|
||||
if (data.user && data.user.username) {
|
||||
if (data.user?.username) {
|
||||
if (!user.equals(data.user)) this.client.actions.UserUpdate.handle(data.user);
|
||||
}
|
||||
|
||||
const guild = this.client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return;
|
||||
|
||||
let oldPresence = guild.presences.cache.get(user.id);
|
||||
if (oldPresence) oldPresence = oldPresence._clone();
|
||||
const oldPresence = guild.presences.cache.get(user.id)?._clone() ?? null;
|
||||
let member = guild.members.cache.get(user.id);
|
||||
if (!member && data.status !== 'offline') {
|
||||
member = guild.members.add({
|
||||
member = guild.members._add({
|
||||
user,
|
||||
roles: data.roles,
|
||||
deaf: false,
|
||||
mute: false,
|
||||
});
|
||||
this.client.emit(Events.GUILD_MEMBER_AVAILABLE, member);
|
||||
}
|
||||
guild.presences.add(Object.assign(data, { guild }));
|
||||
if (member && this.client.listenerCount(Events.PRESENCE_UPDATE)) {
|
||||
const newPresence = guild.presences._add(Object.assign(data, { guild }));
|
||||
if (this.client.listenerCount(Events.PRESENCE_UPDATE) && !newPresence.equals(oldPresence)) {
|
||||
/**
|
||||
* Emitted whenever a guild member's presence (e.g. status, activity) is changed.
|
||||
* @event Client#presenceUpdate
|
||||
* @param {?Presence} oldPresence The presence before the update, if one at all
|
||||
* @param {Presence} newPresence The presence after the update
|
||||
*/
|
||||
this.client.emit(Events.PRESENCE_UPDATE, oldPresence, member.presence);
|
||||
this.client.emit(Events.PRESENCE_UPDATE, oldPresence, newPresence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
28
src/client/actions/StageInstanceCreate.js
Normal file
28
src/client/actions/StageInstanceCreate.js
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class StageInstanceCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = this.getChannel(data);
|
||||
|
||||
if (channel) {
|
||||
const stageInstance = channel.guild.stageInstances._add(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever a stage instance is created.
|
||||
* @event Client#stageInstanceCreate
|
||||
* @param {StageInstance} stageInstance The created stage instance
|
||||
*/
|
||||
client.emit(Events.STAGE_INSTANCE_CREATE, stageInstance);
|
||||
|
||||
return { stageInstance };
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StageInstanceCreateAction;
|
||||
32
src/client/actions/StageInstanceDelete.js
Normal file
32
src/client/actions/StageInstanceDelete.js
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class StageInstanceDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = this.getChannel(data);
|
||||
|
||||
if (channel) {
|
||||
const stageInstance = channel.guild.stageInstances._add(data);
|
||||
if (stageInstance) {
|
||||
channel.guild.stageInstances.cache.delete(stageInstance.id);
|
||||
stageInstance.deleted = true;
|
||||
|
||||
/**
|
||||
* Emitted whenever a stage instance is deleted.
|
||||
* @event Client#stageInstanceDelete
|
||||
* @param {StageInstance} stageInstance The deleted stage instance
|
||||
*/
|
||||
client.emit(Events.STAGE_INSTANCE_DELETE, stageInstance);
|
||||
|
||||
return { stageInstance };
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StageInstanceDeleteAction;
|
||||
30
src/client/actions/StageInstanceUpdate.js
Normal file
30
src/client/actions/StageInstanceUpdate.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class StageInstanceUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const channel = this.getChannel(data);
|
||||
|
||||
if (channel) {
|
||||
const oldStageInstance = channel.guild.stageInstances.cache.get(data.id)?._clone() ?? null;
|
||||
const newStageInstance = channel.guild.stageInstances._add(data);
|
||||
|
||||
/**
|
||||
* Emitted whenever a stage instance gets updated - e.g. change in topic or privacy level
|
||||
* @event Client#stageInstanceUpdate
|
||||
* @param {?StageInstance} oldStageInstance The stage instance before the update
|
||||
* @param {StageInstance} newStageInstance The stage instance after the update
|
||||
*/
|
||||
client.emit(Events.STAGE_INSTANCE_UPDATE, oldStageInstance, newStageInstance);
|
||||
|
||||
return { oldStageInstance, newStageInstance };
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StageInstanceUpdateAction;
|
||||
23
src/client/actions/ThreadCreate.js
Normal file
23
src/client/actions/ThreadCreate.js
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class ThreadCreateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const existing = client.channels.cache.has(data.id);
|
||||
const thread = client.channels._add(data);
|
||||
if (!existing && thread) {
|
||||
/**
|
||||
* Emitted whenever a thread is created or when the client user is added to a thread.
|
||||
* @event Client#threadCreate
|
||||
* @param {ThreadChannel} thread The thread that was created
|
||||
*/
|
||||
client.emit(Events.THREAD_CREATE, thread);
|
||||
}
|
||||
return { thread };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ThreadCreateAction;
|
||||
30
src/client/actions/ThreadDelete.js
Normal file
30
src/client/actions/ThreadDelete.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class ThreadDeleteAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const thread = client.channels.cache.get(data.id);
|
||||
|
||||
if (thread) {
|
||||
client.channels._remove(thread.id);
|
||||
thread.deleted = true;
|
||||
for (const message of thread.messages.cache.values()) {
|
||||
message.deleted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever a thread is deleted.
|
||||
* @event Client#threadDelete
|
||||
* @param {ThreadChannel} thread The thread that was deleted
|
||||
*/
|
||||
client.emit(Events.THREAD_DELETE, thread);
|
||||
}
|
||||
|
||||
return { thread };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ThreadDeleteAction;
|
||||
59
src/client/actions/ThreadListSync.js
Normal file
59
src/client/actions/ThreadListSync.js
Normal file
@@ -0,0 +1,59 @@
|
||||
'use strict';
|
||||
|
||||
const { Collection } = require('@discordjs/collection');
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class ThreadListSyncAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (!guild) return {};
|
||||
|
||||
if (data.channel_ids) {
|
||||
for (const id of data.channel_ids) {
|
||||
const channel = client.channels.resolve(id);
|
||||
if (channel) this.removeStale(channel);
|
||||
}
|
||||
} else {
|
||||
for (const channel of guild.channels.cache.values()) {
|
||||
this.removeStale(channel);
|
||||
}
|
||||
}
|
||||
|
||||
const syncedThreads = data.threads.reduce((coll, rawThread) => {
|
||||
const thread = client.channels._add(rawThread);
|
||||
return coll.set(thread.id, thread);
|
||||
}, new Collection());
|
||||
|
||||
for (const rawMember of Object.values(data.members)) {
|
||||
// Discord sends the thread id as id in this object
|
||||
const thread = client.channels.cache.get(rawMember.id);
|
||||
if (thread) {
|
||||
thread.members._add(rawMember);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted whenever the client user gains access to a text or news channel that contains threads
|
||||
* @event Client#threadListSync
|
||||
* @param {Collection<Snowflake, ThreadChannel>} threads The threads that were synced
|
||||
*/
|
||||
client.emit(Events.THREAD_LIST_SYNC, syncedThreads);
|
||||
|
||||
return {
|
||||
syncedThreads,
|
||||
};
|
||||
}
|
||||
|
||||
removeStale(channel) {
|
||||
channel.threads?.cache.forEach(thread => {
|
||||
if (!thread.archived) {
|
||||
this.client.channels._remove(thread.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ThreadListSyncAction;
|
||||
30
src/client/actions/ThreadMemberUpdate.js
Normal file
30
src/client/actions/ThreadMemberUpdate.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class ThreadMemberUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
// Discord sends the thread id as id in this object
|
||||
const thread = client.channels.cache.get(data.id);
|
||||
if (thread) {
|
||||
const member = thread.members.cache.get(data.user_id);
|
||||
if (!member) {
|
||||
const newMember = thread.members._add(data);
|
||||
return { newMember };
|
||||
}
|
||||
const old = member._update(data);
|
||||
/**
|
||||
* Emitted whenever the client user's thread member is updated.
|
||||
* @event Client#threadMemberUpdate
|
||||
* @param {ThreadMember} oldMember The member before the update
|
||||
* @param {ThreadMember} newMember The member after the update
|
||||
*/
|
||||
client.emit(Events.THREAD_MEMBER_UPDATE, old, member);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ThreadMemberUpdateAction;
|
||||
34
src/client/actions/ThreadMembersUpdate.js
Normal file
34
src/client/actions/ThreadMembersUpdate.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
class ThreadMembersUpdateAction extends Action {
|
||||
handle(data) {
|
||||
const client = this.client;
|
||||
const thread = client.channels.cache.get(data.id);
|
||||
if (thread) {
|
||||
const old = thread.members.cache.clone();
|
||||
thread.memberCount = data.member_count;
|
||||
|
||||
data.added_members?.forEach(rawMember => {
|
||||
thread.members._add(rawMember);
|
||||
});
|
||||
|
||||
data.removed_member_ids?.forEach(memberId => {
|
||||
thread.members.cache.delete(memberId);
|
||||
});
|
||||
|
||||
/**
|
||||
* Emitted whenever members are added or removed from a thread. Requires `GUILD_MEMBERS` privileged intent
|
||||
* @event Client#threadMembersUpdate
|
||||
* @param {Collection<Snowflake, ThreadMember>} oldMembers The members before the update
|
||||
* @param {Collection<Snowflake, ThreadMember>} newMembers The members after the update
|
||||
*/
|
||||
client.emit(Events.THREAD_MEMBERS_UPDATE, old, thread.members.cache);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ThreadMembersUpdateAction;
|
||||
30
src/client/actions/TypingStart.js
Normal file
30
src/client/actions/TypingStart.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
const Action = require('./Action');
|
||||
const Typing = require('../../structures/Typing');
|
||||
const { Events, TextBasedChannelTypes } = require('../../util/Constants');
|
||||
|
||||
class TypingStart extends Action {
|
||||
handle(data) {
|
||||
const channel = this.getChannel(data);
|
||||
if (!channel) {
|
||||
return;
|
||||
}
|
||||
if (!TextBasedChannelTypes.includes(channel.type)) {
|
||||
this.client.emit(Events.WARN, `Discord sent a typing packet to a ${channel.type} channel ${channel.id}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const user = this.getUserFromMember(data);
|
||||
if (channel && user) {
|
||||
/**
|
||||
* Emitted whenever a user starts typing in a channel.
|
||||
* @event Client#typingStart
|
||||
* @param {Typing} typing The typing state
|
||||
*/
|
||||
this.client.emit(Events.TYPING_START, new Typing(channel, user, data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TypingStart;
|
||||
@@ -13,6 +13,7 @@ class UserUpdateAction extends Action {
|
||||
if (!oldUser.equals(newUser)) {
|
||||
/**
|
||||
* Emitted whenever a user's details (e.g. username) are changed.
|
||||
* Triggered by the Discord gateway events USER_UPDATE, GUILD_MEMBER_UPDATE, and PRESENCE_UPDATE.
|
||||
* @event Client#userUpdate
|
||||
* @param {User} oldUser The user before the update
|
||||
* @param {User} newUser The user after the update
|
||||
|
||||
@@ -10,22 +10,21 @@ class VoiceStateUpdate extends Action {
|
||||
const guild = client.guilds.cache.get(data.guild_id);
|
||||
if (guild) {
|
||||
// Update the state
|
||||
const oldState = guild.voiceStates.cache.has(data.user_id)
|
||||
? guild.voiceStates.cache.get(data.user_id)._clone()
|
||||
: new VoiceState(guild, { user_id: data.user_id });
|
||||
const oldState =
|
||||
guild.voiceStates.cache.get(data.user_id)?._clone() ?? new VoiceState(guild, { user_id: data.user_id });
|
||||
|
||||
const newState = guild.voiceStates.add(data);
|
||||
const newState = guild.voiceStates._add(data);
|
||||
|
||||
// Get the member
|
||||
let member = guild.members.cache.get(data.user_id);
|
||||
if (member && data.member) {
|
||||
member._patch(data.member);
|
||||
} else if (data.member && data.member.user && data.member.joined_at) {
|
||||
member = guild.members.add(data.member);
|
||||
} else if (data.member?.user && data.member.joined_at) {
|
||||
member = guild.members._add(data.member);
|
||||
}
|
||||
|
||||
// Emit event
|
||||
if (member && member.user.id === client.user.id) {
|
||||
if (member?.user.id === client.user.id) {
|
||||
client.emit('debug', `[VOICE] received voice state update: ${JSON.stringify(data)}`);
|
||||
client.voice.onVoiceStateUpdate(data);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const VoiceBroadcast = require('./VoiceBroadcast');
|
||||
const VoiceConnection = require('./VoiceConnection');
|
||||
const { Error } = require('../../errors');
|
||||
const Collection = require('../../util/Collection');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
/**
|
||||
* Manages voice connections for the client
|
||||
@@ -19,92 +16,29 @@ class ClientVoiceManager {
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
|
||||
/**
|
||||
* A collection mapping connection IDs to the Connection objects
|
||||
* @type {Collection<Snowflake, VoiceConnection>}
|
||||
* Maps guild ids to voice adapters created for use with @discordjs/voice.
|
||||
* @type {Map<Snowflake, Object>}
|
||||
*/
|
||||
this.connections = new Collection();
|
||||
this.adapters = new Map();
|
||||
|
||||
/**
|
||||
* Active voice broadcasts that have been created
|
||||
* @type {VoiceBroadcast[]}
|
||||
*/
|
||||
this.broadcasts = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a voice broadcast.
|
||||
* @returns {VoiceBroadcast}
|
||||
*/
|
||||
createBroadcast() {
|
||||
const broadcast = new VoiceBroadcast(this.client);
|
||||
this.broadcasts.push(broadcast);
|
||||
return broadcast;
|
||||
}
|
||||
|
||||
onVoiceServer({ guild_id, token, endpoint }) {
|
||||
this.client.emit('debug', `[VOICE] voiceServer guild: ${guild_id} token: ${token} endpoint: ${endpoint}`);
|
||||
const connection = this.connections.get(guild_id);
|
||||
if (connection) connection.setTokenAndEndpoint(token, endpoint);
|
||||
}
|
||||
|
||||
onVoiceStateUpdate({ guild_id, session_id, channel_id }) {
|
||||
const connection = this.connections.get(guild_id);
|
||||
this.client.emit('debug', `[VOICE] connection? ${!!connection}, ${guild_id} ${session_id} ${channel_id}`);
|
||||
if (!connection) return;
|
||||
if (!channel_id) {
|
||||
connection._disconnect();
|
||||
this.connections.delete(guild_id);
|
||||
return;
|
||||
}
|
||||
connection.channel = this.client.channels.cache.get(channel_id);
|
||||
connection.setSessionID(session_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up a request to join a voice channel.
|
||||
* @param {VoiceChannel} channel The voice channel to join
|
||||
* @returns {Promise<VoiceConnection>}
|
||||
* @private
|
||||
*/
|
||||
joinChannel(channel) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!channel.joinable) {
|
||||
throw new Error('VOICE_JOIN_CHANNEL', channel.full);
|
||||
}
|
||||
|
||||
let connection = this.connections.get(channel.guild.id);
|
||||
|
||||
if (connection) {
|
||||
if (connection.channel.id !== channel.id) {
|
||||
this.connections.get(channel.guild.id).updateChannel(channel);
|
||||
client.on(Events.SHARD_DISCONNECT, (_, shardId) => {
|
||||
for (const [guildId, adapter] of this.adapters.entries()) {
|
||||
if (client.guilds.cache.get(guildId)?.shardId === shardId) {
|
||||
adapter.destroy();
|
||||
}
|
||||
resolve(connection);
|
||||
return;
|
||||
} else {
|
||||
connection = new VoiceConnection(this, channel);
|
||||
connection.on('debug', msg =>
|
||||
this.client.emit('debug', `[VOICE (${channel.guild.id}:${connection.status})]: ${msg}`),
|
||||
);
|
||||
connection.authenticate();
|
||||
this.connections.set(channel.guild.id, connection);
|
||||
}
|
||||
|
||||
connection.once('failed', reason => {
|
||||
this.connections.delete(channel.guild.id);
|
||||
reject(reason);
|
||||
});
|
||||
|
||||
connection.on('error', reject);
|
||||
|
||||
connection.once('authenticated', () => {
|
||||
connection.once('ready', () => {
|
||||
resolve(connection);
|
||||
connection.removeListener('error', reject);
|
||||
});
|
||||
connection.once('disconnect', () => this.connections.delete(channel.guild.id));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onVoiceServer(payload) {
|
||||
this.adapters.get(payload.guild_id)?.onVoiceServerUpdate(payload);
|
||||
}
|
||||
|
||||
onVoiceStateUpdate(payload) {
|
||||
if (payload.guild_id && payload.session_id && payload.user_id === this.client.user?.id) {
|
||||
this.adapters.get(payload.guild_id)?.onVoiceStateUpdate(payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClientVoiceManager;
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const BroadcastAudioPlayer = require('./player/BroadcastAudioPlayer');
|
||||
const PlayInterface = require('./util/PlayInterface');
|
||||
const { Events } = require('../../util/Constants');
|
||||
|
||||
/**
|
||||
* A voice broadcast can be played across multiple voice connections for improved shared-stream efficiency.
|
||||
*
|
||||
* Example usage:
|
||||
* ```js
|
||||
* const broadcast = client.voice.createBroadcast();
|
||||
* broadcast.play('./music.mp3');
|
||||
* // Play "music.mp3" in all voice connections that the client is in
|
||||
* for (const connection of client.voice.connections.values()) {
|
||||
* connection.play(broadcast);
|
||||
* }
|
||||
* ```
|
||||
* @implements {PlayInterface}
|
||||
*/
|
||||
class VoiceBroadcast extends EventEmitter {
|
||||
constructor(client) {
|
||||
super();
|
||||
/**
|
||||
* The client that created the broadcast
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = client;
|
||||
/**
|
||||
* The subscribed StreamDispatchers of this broadcast
|
||||
* @type {StreamDispatcher[]}
|
||||
*/
|
||||
this.subscribers = [];
|
||||
this.player = new BroadcastAudioPlayer(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* The current master dispatcher, if any. This dispatcher controls all that is played by subscribed dispatchers.
|
||||
* @type {?BroadcastDispatcher}
|
||||
* @readonly
|
||||
*/
|
||||
get dispatcher() {
|
||||
return this.player.dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Play an audio resource.
|
||||
* @param {ReadableStream|string} resource The resource to play.
|
||||
* @param {StreamOptions} [options] The options to play.
|
||||
* @example
|
||||
* // Play a local audio file
|
||||
* broadcast.play('/home/hydrabolt/audio.mp3', { volume: 0.5 });
|
||||
* @example
|
||||
* // Play a ReadableStream
|
||||
* broadcast.play(ytdl('https://www.youtube.com/watch?v=ZlAU_w7-Xp8', { filter: 'audioonly' }));
|
||||
* @example
|
||||
* // Using different protocols: https://ffmpeg.org/ffmpeg-protocols.html
|
||||
* broadcast.play('http://www.sample-videos.com/audio/mp3/wave.mp3');
|
||||
* @returns {BroadcastDispatcher}
|
||||
*/
|
||||
play() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the broadcast, unsubscribing all subscribed channels and deleting the broadcast
|
||||
*/
|
||||
end() {
|
||||
for (const dispatcher of this.subscribers) this.delete(dispatcher);
|
||||
const index = this.client.voice.broadcasts.indexOf(this);
|
||||
if (index !== -1) this.client.voice.broadcasts.splice(index, 1);
|
||||
}
|
||||
|
||||
add(dispatcher) {
|
||||
const index = this.subscribers.indexOf(dispatcher);
|
||||
if (index === -1) {
|
||||
this.subscribers.push(dispatcher);
|
||||
/**
|
||||
* Emitted whenever a stream dispatcher subscribes to the broadcast.
|
||||
* @event VoiceBroadcast#subscribe
|
||||
* @param {StreamDispatcher} subscriber The subscribed dispatcher
|
||||
*/
|
||||
this.emit(Events.VOICE_BROADCAST_SUBSCRIBE, dispatcher);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
delete(dispatcher) {
|
||||
const index = this.subscribers.indexOf(dispatcher);
|
||||
if (index !== -1) {
|
||||
this.subscribers.splice(index, 1);
|
||||
dispatcher.destroy();
|
||||
/**
|
||||
* Emitted whenever a stream dispatcher unsubscribes to the broadcast.
|
||||
* @event VoiceBroadcast#unsubscribe
|
||||
* @param {StreamDispatcher} dispatcher The unsubscribed dispatcher
|
||||
*/
|
||||
this.emit(Events.VOICE_BROADCAST_UNSUBSCRIBE, dispatcher);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
PlayInterface.applyToClass(VoiceBroadcast);
|
||||
|
||||
module.exports = VoiceBroadcast;
|
||||
@@ -1,523 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const VoiceUDP = require('./networking/VoiceUDPClient');
|
||||
const VoiceWebSocket = require('./networking/VoiceWebSocket');
|
||||
const AudioPlayer = require('./player/AudioPlayer');
|
||||
const VoiceReceiver = require('./receiver/Receiver');
|
||||
const PlayInterface = require('./util/PlayInterface');
|
||||
const Silence = require('./util/Silence');
|
||||
const { Error } = require('../../errors');
|
||||
const { OPCodes, VoiceOPCodes, VoiceStatus, Events } = require('../../util/Constants');
|
||||
const Speaking = require('../../util/Speaking');
|
||||
const Util = require('../../util/Util');
|
||||
|
||||
// Workaround for Discord now requiring silence to be sent before being able to receive audio
|
||||
class SingleSilence extends Silence {
|
||||
_read() {
|
||||
super._read();
|
||||
this.push(null);
|
||||
}
|
||||
}
|
||||
|
||||
const SUPPORTED_MODES = ['xsalsa20_poly1305_lite', 'xsalsa20_poly1305_suffix', 'xsalsa20_poly1305'];
|
||||
|
||||
/**
|
||||
* Represents a connection to a guild's voice server.
|
||||
* ```js
|
||||
* // Obtained using:
|
||||
* voiceChannel.join()
|
||||
* .then(connection => {
|
||||
*
|
||||
* });
|
||||
* ```
|
||||
* @extends {EventEmitter}
|
||||
* @implements {PlayInterface}
|
||||
*/
|
||||
class VoiceConnection extends EventEmitter {
|
||||
constructor(voiceManager, channel) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The voice manager that instantiated this connection
|
||||
* @type {ClientVoiceManager}
|
||||
*/
|
||||
this.voiceManager = voiceManager;
|
||||
|
||||
/**
|
||||
* The voice channel this connection is currently serving
|
||||
* @type {VoiceChannel}
|
||||
*/
|
||||
this.channel = channel;
|
||||
|
||||
/**
|
||||
* The current status of the voice connection
|
||||
* @type {VoiceStatus}
|
||||
*/
|
||||
this.status = VoiceStatus.AUTHENTICATING;
|
||||
|
||||
/**
|
||||
* Our current speaking state
|
||||
* @type {Readonly<Speaking>}
|
||||
*/
|
||||
this.speaking = new Speaking().freeze();
|
||||
|
||||
/**
|
||||
* The authentication data needed to connect to the voice server
|
||||
* @type {Object}
|
||||
* @private
|
||||
*/
|
||||
this.authentication = {};
|
||||
|
||||
/**
|
||||
* The audio player for this voice connection
|
||||
* @type {AudioPlayer}
|
||||
*/
|
||||
this.player = new AudioPlayer(this);
|
||||
|
||||
this.player.on('debug', m => {
|
||||
/**
|
||||
* Debug info from the connection.
|
||||
* @event VoiceConnection#debug
|
||||
* @param {string} message The debug message
|
||||
*/
|
||||
this.emit('debug', `audio player - ${m}`);
|
||||
});
|
||||
|
||||
this.player.on('error', e => {
|
||||
/**
|
||||
* Warning info from the connection.
|
||||
* @event VoiceConnection#warn
|
||||
* @param {string|Error} warning The warning
|
||||
*/
|
||||
this.emit('warn', e);
|
||||
});
|
||||
|
||||
this.once('closing', () => this.player.destroy());
|
||||
|
||||
/**
|
||||
* Map SSRC values to user IDs
|
||||
* @type {Map<number, Snowflake>}
|
||||
* @private
|
||||
*/
|
||||
this.ssrcMap = new Map();
|
||||
|
||||
/**
|
||||
* Tracks which users are talking
|
||||
* @type {Map<Snowflake, Readonly<Speaking>>}
|
||||
* @private
|
||||
*/
|
||||
this._speaking = new Map();
|
||||
|
||||
/**
|
||||
* Object that wraps contains the `ws` and `udp` sockets of this voice connection
|
||||
* @type {Object}
|
||||
* @private
|
||||
*/
|
||||
this.sockets = {};
|
||||
|
||||
/**
|
||||
* The voice receiver of this connection
|
||||
* @type {VoiceReceiver}
|
||||
*/
|
||||
this.receiver = new VoiceReceiver(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* The client that instantiated this connection
|
||||
* @type {Client}
|
||||
* @readonly
|
||||
*/
|
||||
get client() {
|
||||
return this.voiceManager.client;
|
||||
}
|
||||
|
||||
/**
|
||||
* The current stream dispatcher (if any)
|
||||
* @type {?StreamDispatcher}
|
||||
* @readonly
|
||||
*/
|
||||
get dispatcher() {
|
||||
return this.player.dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the voice connection should display as "speaking", "soundshare" or "none".
|
||||
* @param {BitFieldResolvable} value The new speaking state
|
||||
* @private
|
||||
*/
|
||||
setSpeaking(value) {
|
||||
if (this.speaking.equals(value)) return;
|
||||
if (this.status !== VoiceStatus.CONNECTED) return;
|
||||
this.speaking = new Speaking(value).freeze();
|
||||
this.sockets.ws
|
||||
.sendPacket({
|
||||
op: VoiceOPCodes.SPEAKING,
|
||||
d: {
|
||||
speaking: this.speaking.bitfield,
|
||||
delay: 0,
|
||||
ssrc: this.authentication.ssrc,
|
||||
},
|
||||
})
|
||||
.catch(e => {
|
||||
this.emit('debug', e);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The voice state of this connection
|
||||
* @type {VoiceState}
|
||||
*/
|
||||
get voice() {
|
||||
return this.channel.guild.voice;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a request to the main gateway to join a voice channel.
|
||||
* @param {Object} [options] The options to provide
|
||||
* @returns {Promise<Shard>}
|
||||
* @private
|
||||
*/
|
||||
sendVoiceStateUpdate(options = {}) {
|
||||
options = Util.mergeDefault(
|
||||
{
|
||||
guild_id: this.channel.guild.id,
|
||||
channel_id: this.channel.id,
|
||||
self_mute: this.voice ? this.voice.selfMute : false,
|
||||
self_deaf: this.voice ? this.voice.selfDeaf : false,
|
||||
},
|
||||
options,
|
||||
);
|
||||
|
||||
this.emit('debug', `Sending voice state update: ${JSON.stringify(options)}`);
|
||||
|
||||
return this.channel.guild.shard.send(
|
||||
{
|
||||
op: OPCodes.VOICE_STATE_UPDATE,
|
||||
d: options,
|
||||
},
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the token and endpoint required to connect to the voice servers.
|
||||
* @param {string} token The voice token
|
||||
* @param {string} endpoint The voice endpoint
|
||||
* @private
|
||||
* @returns {void}
|
||||
*/
|
||||
setTokenAndEndpoint(token, endpoint) {
|
||||
this.emit('debug', `Token "${token}" and endpoint "${endpoint}"`);
|
||||
if (!endpoint) {
|
||||
// Signifies awaiting endpoint stage
|
||||
return;
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
this.authenticateFailed('VOICE_TOKEN_ABSENT');
|
||||
return;
|
||||
}
|
||||
|
||||
endpoint = endpoint.match(/([^:]*)/)[0];
|
||||
this.emit('debug', `Endpoint resolved as ${endpoint}`);
|
||||
|
||||
if (!endpoint) {
|
||||
this.authenticateFailed('VOICE_INVALID_ENDPOINT');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.status === VoiceStatus.AUTHENTICATING) {
|
||||
this.authentication.token = token;
|
||||
this.authentication.endpoint = endpoint;
|
||||
this.checkAuthenticated();
|
||||
} else if (token !== this.authentication.token || endpoint !== this.authentication.endpoint) {
|
||||
this.reconnect(token, endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Session ID for the connection.
|
||||
* @param {string} sessionID The voice session ID
|
||||
* @private
|
||||
*/
|
||||
setSessionID(sessionID) {
|
||||
this.emit('debug', `Setting sessionID ${sessionID} (stored as "${this.authentication.sessionID}")`);
|
||||
if (!sessionID) {
|
||||
this.authenticateFailed('VOICE_SESSION_ABSENT');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.status === VoiceStatus.AUTHENTICATING) {
|
||||
this.authentication.sessionID = sessionID;
|
||||
this.checkAuthenticated();
|
||||
} else if (sessionID !== this.authentication.sessionID) {
|
||||
this.authentication.sessionID = sessionID;
|
||||
/**
|
||||
* Emitted when a new session ID is received.
|
||||
* @event VoiceConnection#newSession
|
||||
* @private
|
||||
*/
|
||||
this.emit('newSession', sessionID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the voice connection is authenticated.
|
||||
* @private
|
||||
*/
|
||||
checkAuthenticated() {
|
||||
const { token, endpoint, sessionID } = this.authentication;
|
||||
this.emit('debug', `Authenticated with sessionID ${sessionID}`);
|
||||
if (token && endpoint && sessionID) {
|
||||
this.status = VoiceStatus.CONNECTING;
|
||||
/**
|
||||
* Emitted when we successfully initiate a voice connection.
|
||||
* @event VoiceConnection#authenticated
|
||||
*/
|
||||
this.emit('authenticated');
|
||||
this.connect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when we fail to initiate a voice connection.
|
||||
* @param {string} reason The reason for failure
|
||||
* @private
|
||||
*/
|
||||
authenticateFailed(reason) {
|
||||
this.client.clearTimeout(this.connectTimeout);
|
||||
this.emit('debug', `Authenticate failed - ${reason}`);
|
||||
if (this.status === VoiceStatus.AUTHENTICATING) {
|
||||
/**
|
||||
* Emitted when we fail to initiate a voice connection.
|
||||
* @event VoiceConnection#failed
|
||||
* @param {Error} error The encountered error
|
||||
*/
|
||||
this.emit('failed', new Error(reason));
|
||||
} else {
|
||||
/**
|
||||
* Emitted whenever the connection encounters an error.
|
||||
* @event VoiceConnection#error
|
||||
* @param {Error} error The encountered error
|
||||
*/
|
||||
this.emit('error', new Error(reason));
|
||||
}
|
||||
this.status = VoiceStatus.DISCONNECTED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move to a different voice channel in the same guild.
|
||||
* @param {VoiceChannel} channel The channel to move to
|
||||
* @private
|
||||
*/
|
||||
updateChannel(channel) {
|
||||
this.channel = channel;
|
||||
this.sendVoiceStateUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to authenticate to the voice server.
|
||||
* @private
|
||||
*/
|
||||
authenticate() {
|
||||
this.sendVoiceStateUpdate();
|
||||
this.connectTimeout = this.client.setTimeout(() => this.authenticateFailed('VOICE_CONNECTION_TIMEOUT'), 15000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to reconnect to the voice server (typically after a region change).
|
||||
* @param {string} token The voice token
|
||||
* @param {string} endpoint The voice endpoint
|
||||
* @private
|
||||
*/
|
||||
reconnect(token, endpoint) {
|
||||
this.authentication.token = token;
|
||||
this.authentication.endpoint = endpoint;
|
||||
this.speaking = new Speaking().freeze();
|
||||
this.status = VoiceStatus.RECONNECTING;
|
||||
this.emit('debug', `Reconnecting to ${endpoint}`);
|
||||
/**
|
||||
* Emitted when the voice connection is reconnecting (typically after a region change).
|
||||
* @event VoiceConnection#reconnecting
|
||||
*/
|
||||
this.emit('reconnecting');
|
||||
this.connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the voice connection, causing a disconnect and closing event to be emitted.
|
||||
*/
|
||||
disconnect() {
|
||||
this.emit('closing');
|
||||
this.emit('debug', 'disconnect() triggered');
|
||||
this.client.clearTimeout(this.connectTimeout);
|
||||
const conn = this.voiceManager.connections.get(this.channel.guild.id);
|
||||
if (conn === this) this.voiceManager.connections.delete(this.channel.guild.id);
|
||||
this.sendVoiceStateUpdate({
|
||||
channel_id: null,
|
||||
});
|
||||
this._disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Internally disconnects (doesn't send disconnect packet).
|
||||
* @private
|
||||
*/
|
||||
_disconnect() {
|
||||
this.cleanup();
|
||||
this.status = VoiceStatus.DISCONNECTED;
|
||||
/**
|
||||
* Emitted when the voice connection disconnects.
|
||||
* @event VoiceConnection#disconnect
|
||||
*/
|
||||
this.emit('disconnect');
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up after disconnect.
|
||||
* @private
|
||||
*/
|
||||
cleanup() {
|
||||
this.player.destroy();
|
||||
this.speaking = new Speaking().freeze();
|
||||
const { ws, udp } = this.sockets;
|
||||
|
||||
this.emit('debug', 'Connection clean up');
|
||||
|
||||
if (ws) {
|
||||
ws.removeAllListeners('error');
|
||||
ws.removeAllListeners('ready');
|
||||
ws.removeAllListeners('sessionDescription');
|
||||
ws.removeAllListeners('speaking');
|
||||
ws.shutdown();
|
||||
}
|
||||
|
||||
if (udp) udp.removeAllListeners('error');
|
||||
|
||||
this.sockets.ws = null;
|
||||
this.sockets.udp = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect the voice connection.
|
||||
* @private
|
||||
*/
|
||||
connect() {
|
||||
this.emit('debug', `Connect triggered`);
|
||||
if (this.status !== VoiceStatus.RECONNECTING) {
|
||||
if (this.sockets.ws) throw new Error('WS_CONNECTION_EXISTS');
|
||||
if (this.sockets.udp) throw new Error('UDP_CONNECTION_EXISTS');
|
||||
}
|
||||
|
||||
if (this.sockets.ws) this.sockets.ws.shutdown();
|
||||
if (this.sockets.udp) this.sockets.udp.shutdown();
|
||||
|
||||
this.sockets.ws = new VoiceWebSocket(this);
|
||||
this.sockets.udp = new VoiceUDP(this);
|
||||
|
||||
const { ws, udp } = this.sockets;
|
||||
|
||||
ws.on('debug', msg => this.emit('debug', msg));
|
||||
udp.on('debug', msg => this.emit('debug', msg));
|
||||
ws.on('error', err => this.emit('error', err));
|
||||
udp.on('error', err => this.emit('error', err));
|
||||
ws.on('ready', this.onReady.bind(this));
|
||||
ws.on('sessionDescription', this.onSessionDescription.bind(this));
|
||||
ws.on('startSpeaking', this.onStartSpeaking.bind(this));
|
||||
|
||||
this.sockets.ws.connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the voice websocket is ready.
|
||||
* @param {Object} data The received data
|
||||
* @private
|
||||
*/
|
||||
onReady(data) {
|
||||
Object.assign(this.authentication, data);
|
||||
for (let mode of data.modes) {
|
||||
if (SUPPORTED_MODES.includes(mode)) {
|
||||
this.authentication.mode = mode;
|
||||
this.emit('debug', `Selecting the ${mode} mode`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.sockets.udp.createUDPSocket(data.ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when a session description is received.
|
||||
* @param {Object} data The received data
|
||||
* @private
|
||||
*/
|
||||
onSessionDescription(data) {
|
||||
Object.assign(this.authentication, data);
|
||||
this.status = VoiceStatus.CONNECTED;
|
||||
const ready = () => {
|
||||
this.client.clearTimeout(this.connectTimeout);
|
||||
this.emit('debug', `Ready with authentication details: ${JSON.stringify(this.authentication)}`);
|
||||
/**
|
||||
* Emitted once the connection is ready, when a promise to join a voice channel resolves,
|
||||
* the connection will already be ready.
|
||||
* @event VoiceConnection#ready
|
||||
*/
|
||||
this.emit('ready');
|
||||
};
|
||||
if (this.dispatcher) {
|
||||
ready();
|
||||
} else {
|
||||
// This serves to provide support for voice receive, sending audio is required to receive it.
|
||||
const dispatcher = this.play(new SingleSilence(), { type: 'opus', volume: false });
|
||||
dispatcher.once('finish', ready);
|
||||
}
|
||||
}
|
||||
|
||||
onStartSpeaking({ user_id, ssrc, speaking }) {
|
||||
this.ssrcMap.set(+ssrc, { userID: user_id, speaking: speaking });
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when a speaking event is received.
|
||||
* @param {Object} data The received data
|
||||
* @private
|
||||
*/
|
||||
onSpeaking({ user_id, speaking }) {
|
||||
speaking = new Speaking(speaking).freeze();
|
||||
const guild = this.channel.guild;
|
||||
const user = this.client.users.cache.get(user_id);
|
||||
const old = this._speaking.get(user_id);
|
||||
this._speaking.set(user_id, speaking);
|
||||
/**
|
||||
* Emitted whenever a user changes speaking state.
|
||||
* @event VoiceConnection#speaking
|
||||
* @param {User} user The user that has changed speaking state
|
||||
* @param {Readonly<Speaking>} speaking The speaking state of the user
|
||||
*/
|
||||
if (this.status === VoiceStatus.CONNECTED) {
|
||||
this.emit('speaking', user, speaking);
|
||||
if (!speaking.has(Speaking.FLAGS.SPEAKING)) {
|
||||
this.receiver.packets._stoppedSpeaking(user_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (guild && user && !speaking.equals(old)) {
|
||||
const member = guild.member(user);
|
||||
if (member) {
|
||||
/**
|
||||
* Emitted once a guild member changes speaking state.
|
||||
* @event Client#guildMemberSpeaking
|
||||
* @param {GuildMember} member The member that started/stopped speaking
|
||||
* @param {Readonly<Speaking>} speaking The speaking state of the member
|
||||
*/
|
||||
this.client.emit(Events.GUILD_MEMBER_SPEAKING, member, speaking);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
play() {} // eslint-disable-line no-empty-function
|
||||
}
|
||||
|
||||
PlayInterface.applyToClass(VoiceConnection);
|
||||
|
||||
module.exports = VoiceConnection;
|
||||
@@ -1,46 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const StreamDispatcher = require('./StreamDispatcher');
|
||||
|
||||
/**
|
||||
* The class that sends voice packet data to the voice connection.
|
||||
* @implements {VolumeInterface}
|
||||
* @extends {StreamDispatcher}
|
||||
*/
|
||||
class BroadcastDispatcher extends StreamDispatcher {
|
||||
constructor(player, options, streams) {
|
||||
super(player, options, streams);
|
||||
this.broadcast = player.broadcast;
|
||||
}
|
||||
|
||||
_write(chunk, enc, done) {
|
||||
if (!this.startTime) this.startTime = Date.now();
|
||||
for (const dispatcher of this.broadcast.subscribers) {
|
||||
dispatcher._write(chunk, enc);
|
||||
}
|
||||
this._step(done);
|
||||
}
|
||||
|
||||
_destroy(err, cb) {
|
||||
if (this.player.dispatcher === this) this.player.dispatcher = null;
|
||||
const { streams } = this;
|
||||
if (streams.opus) streams.opus.unpipe(this);
|
||||
if (streams.ffmpeg) streams.ffmpeg.destroy();
|
||||
super._destroy(err, cb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bitrate of the current Opus encoder if using a compatible Opus stream.
|
||||
* @param {number} value New bitrate, in kbps
|
||||
* If set to 'auto', 48kbps will be used
|
||||
* @returns {boolean} true if the bitrate has been successfully changed.
|
||||
*/
|
||||
setBitrate(value) {
|
||||
if (!value || !this.streams.opus || !this.streams.opus.setBitrate) return false;
|
||||
const bitrate = value === 'auto' ? 48 : value;
|
||||
this.streams.opus.setBitrate(bitrate * 1000);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BroadcastDispatcher;
|
||||
@@ -1,354 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const { Writable } = require('stream');
|
||||
const secretbox = require('../util/Secretbox');
|
||||
const Silence = require('../util/Silence');
|
||||
const VolumeInterface = require('../util/VolumeInterface');
|
||||
|
||||
const FRAME_LENGTH = 20;
|
||||
const CHANNELS = 2;
|
||||
const TIMESTAMP_INC = (48000 / 100) * CHANNELS;
|
||||
|
||||
const MAX_NONCE_SIZE = 2 ** 32 - 1;
|
||||
const nonce = Buffer.alloc(24);
|
||||
|
||||
/**
|
||||
* @external WritableStream
|
||||
* @see {@link https://nodejs.org/api/stream.html#stream_class_stream_writable}
|
||||
*/
|
||||
|
||||
/**
|
||||
* The class that sends voice packet data to the voice connection.
|
||||
* ```js
|
||||
* // Obtained using:
|
||||
* voiceChannel.join().then(connection => {
|
||||
* // You can play a file or a stream here:
|
||||
* const dispatcher = connection.play('/home/hydrabolt/audio.mp3');
|
||||
* });
|
||||
* ```
|
||||
* @implements {VolumeInterface}
|
||||
* @extends {WritableStream}
|
||||
*/
|
||||
class StreamDispatcher extends Writable {
|
||||
constructor(player, { seek = 0, volume = 1, fec, plp, bitrate = 96, highWaterMark = 12 } = {}, streams) {
|
||||
const streamOptions = { seek, volume, fec, plp, bitrate, highWaterMark };
|
||||
super(streamOptions);
|
||||
/**
|
||||
* The Audio Player that controls this dispatcher
|
||||
* @type {AudioPlayer}
|
||||
*/
|
||||
this.player = player;
|
||||
this.streamOptions = streamOptions;
|
||||
this.streams = streams;
|
||||
this.streams.silence = new Silence();
|
||||
|
||||
this._nonce = 0;
|
||||
this._nonceBuffer = Buffer.alloc(24);
|
||||
|
||||
/**
|
||||
* The time that the stream was paused at (null if not paused)
|
||||
* @type {?number}
|
||||
*/
|
||||
this.pausedSince = null;
|
||||
this._writeCallback = null;
|
||||
|
||||
/**
|
||||
* The broadcast controlling this dispatcher, if any
|
||||
* @type {?VoiceBroadcast}
|
||||
*/
|
||||
this.broadcast = this.streams.broadcast;
|
||||
|
||||
this._pausedTime = 0;
|
||||
this._silentPausedTime = 0;
|
||||
this.count = 0;
|
||||
|
||||
this.on('finish', () => {
|
||||
this._cleanup();
|
||||
this._setSpeaking(0);
|
||||
});
|
||||
|
||||
this.setVolume(volume);
|
||||
this.setBitrate(bitrate);
|
||||
if (typeof fec !== 'undefined') this.setFEC(fec);
|
||||
if (typeof plp !== 'undefined') this.setPLP(plp);
|
||||
|
||||
const streamError = (type, err) => {
|
||||
/**
|
||||
* Emitted when the dispatcher encounters an error.
|
||||
* @event StreamDispatcher#error
|
||||
*/
|
||||
if (type && err) {
|
||||
err.message = `${type} stream: ${err.message}`;
|
||||
this.emit(this.player.dispatcher === this ? 'error' : 'debug', err);
|
||||
}
|
||||
this.destroy();
|
||||
};
|
||||
|
||||
this.on('error', () => streamError());
|
||||
if (this.streams.input) this.streams.input.on('error', err => streamError('input', err));
|
||||
if (this.streams.ffmpeg) this.streams.ffmpeg.on('error', err => streamError('ffmpeg', err));
|
||||
if (this.streams.opus) this.streams.opus.on('error', err => streamError('opus', err));
|
||||
if (this.streams.volume) this.streams.volume.on('error', err => streamError('volume', err));
|
||||
}
|
||||
|
||||
get _sdata() {
|
||||
return this.player.streamingData;
|
||||
}
|
||||
|
||||
_write(chunk, enc, done) {
|
||||
if (!this.startTime) {
|
||||
/**
|
||||
* Emitted once the stream has started to play.
|
||||
* @event StreamDispatcher#start
|
||||
*/
|
||||
this.emit('start');
|
||||
this.startTime = Date.now();
|
||||
}
|
||||
this._playChunk(chunk);
|
||||
this._step(done);
|
||||
}
|
||||
|
||||
_destroy(err, cb) {
|
||||
this._cleanup();
|
||||
super._destroy(err, cb);
|
||||
}
|
||||
|
||||
_cleanup() {
|
||||
if (this.player.dispatcher === this) this.player.dispatcher = null;
|
||||
const { streams } = this;
|
||||
if (streams.broadcast) streams.broadcast.delete(this);
|
||||
if (streams.opus) streams.opus.destroy();
|
||||
if (streams.ffmpeg) streams.ffmpeg.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pauses playback
|
||||
* @param {boolean} [silence=false] Whether to play silence while paused to prevent audio glitches
|
||||
*/
|
||||
pause(silence = false) {
|
||||
if (this.paused) return;
|
||||
if (this.streams.opus) this.streams.opus.unpipe(this);
|
||||
if (silence) {
|
||||
this.streams.silence.pipe(this);
|
||||
this._silence = true;
|
||||
} else {
|
||||
this._setSpeaking(0);
|
||||
}
|
||||
this.pausedSince = Date.now();
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not playback is paused
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
*/
|
||||
get paused() {
|
||||
return Boolean(this.pausedSince);
|
||||
}
|
||||
|
||||
/**
|
||||
* Total time that this dispatcher has been paused in milliseconds
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get pausedTime() {
|
||||
return this._silentPausedTime + this._pausedTime + (this.paused ? Date.now() - this.pausedSince : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resumes playback
|
||||
*/
|
||||
resume() {
|
||||
if (!this.pausedSince) return;
|
||||
this.streams.silence.unpipe(this);
|
||||
if (this.streams.opus) this.streams.opus.pipe(this);
|
||||
if (this._silence) {
|
||||
this._silentPausedTime += Date.now() - this.pausedSince;
|
||||
this._silence = false;
|
||||
} else {
|
||||
this._pausedTime += Date.now() - this.pausedSince;
|
||||
}
|
||||
this.pausedSince = null;
|
||||
if (typeof this._writeCallback === 'function') this._writeCallback();
|
||||
}
|
||||
|
||||
/**
|
||||
* The time (in milliseconds) that the dispatcher has actually been playing audio for
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get streamTime() {
|
||||
return this.count * FRAME_LENGTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* The time (in milliseconds) that the dispatcher has been playing audio for, taking into account skips and pauses
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get totalStreamTime() {
|
||||
return Date.now() - this.startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bitrate of the current Opus encoder if using a compatible Opus stream.
|
||||
* @param {number} value New bitrate, in kbps
|
||||
* If set to 'auto', the voice channel's bitrate will be used
|
||||
* @returns {boolean} true if the bitrate has been successfully changed.
|
||||
*/
|
||||
setBitrate(value) {
|
||||
if (!value || !this.bitrateEditable) return false;
|
||||
const bitrate = value === 'auto' ? this.player.voiceConnection.channel.bitrate : value;
|
||||
this.streams.opus.setBitrate(bitrate * 1000);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the expected packet loss percentage if using a compatible Opus stream.
|
||||
* @param {number} value between 0 and 1
|
||||
* @returns {boolean} Returns true if it was successfully set.
|
||||
*/
|
||||
setPLP(value) {
|
||||
if (!this.bitrateEditable) return false;
|
||||
this.streams.opus.setPLP(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables forward error correction if using a compatible Opus stream.
|
||||
* @param {boolean} enabled true to enable
|
||||
* @returns {boolean} Returns true if it was successfully set.
|
||||
*/
|
||||
setFEC(enabled) {
|
||||
if (!this.bitrateEditable) return false;
|
||||
this.streams.opus.setFEC(enabled);
|
||||
return true;
|
||||
}
|
||||
|
||||
_step(done) {
|
||||
this._writeCallback = () => {
|
||||
this._writeCallback = null;
|
||||
done();
|
||||
};
|
||||
if (!this.streams.broadcast) {
|
||||
const next = FRAME_LENGTH + this.count * FRAME_LENGTH - (Date.now() - this.startTime - this._pausedTime);
|
||||
setTimeout(() => {
|
||||
if ((!this.pausedSince || this._silence) && this._writeCallback) this._writeCallback();
|
||||
}, next);
|
||||
}
|
||||
this._sdata.sequence++;
|
||||
this._sdata.timestamp += TIMESTAMP_INC;
|
||||
if (this._sdata.sequence >= 2 ** 16) this._sdata.sequence = 0;
|
||||
if (this._sdata.timestamp >= 2 ** 32) this._sdata.timestamp = 0;
|
||||
this.count++;
|
||||
}
|
||||
|
||||
_final(callback) {
|
||||
this._writeCallback = null;
|
||||
callback();
|
||||
}
|
||||
|
||||
_playChunk(chunk) {
|
||||
if (this.player.dispatcher !== this || !this.player.voiceConnection.authentication.secret_key) return;
|
||||
this._sendPacket(this._createPacket(this._sdata.sequence, this._sdata.timestamp, chunk));
|
||||
}
|
||||
|
||||
_encrypt(buffer) {
|
||||
const { secret_key, mode } = this.player.voiceConnection.authentication;
|
||||
if (mode === 'xsalsa20_poly1305_lite') {
|
||||
this._nonce++;
|
||||
if (this._nonce > MAX_NONCE_SIZE) this._nonce = 0;
|
||||
this._nonceBuffer.writeUInt32BE(this._nonce, 0);
|
||||
return [secretbox.methods.close(buffer, this._nonceBuffer, secret_key), this._nonceBuffer.slice(0, 4)];
|
||||
} else if (mode === 'xsalsa20_poly1305_suffix') {
|
||||
const random = secretbox.methods.random(24);
|
||||
return [secretbox.methods.close(buffer, random, secret_key), random];
|
||||
} else {
|
||||
return [secretbox.methods.close(buffer, nonce, secret_key)];
|
||||
}
|
||||
}
|
||||
|
||||
_createPacket(sequence, timestamp, buffer) {
|
||||
const packetBuffer = Buffer.alloc(12);
|
||||
packetBuffer[0] = 0x80;
|
||||
packetBuffer[1] = 0x78;
|
||||
|
||||
packetBuffer.writeUIntBE(sequence, 2, 2);
|
||||
packetBuffer.writeUIntBE(timestamp, 4, 4);
|
||||
packetBuffer.writeUIntBE(this.player.voiceConnection.authentication.ssrc, 8, 4);
|
||||
|
||||
packetBuffer.copy(nonce, 0, 0, 12);
|
||||
return Buffer.concat([packetBuffer, ...this._encrypt(buffer)]);
|
||||
}
|
||||
|
||||
_sendPacket(packet) {
|
||||
/**
|
||||
* Emitted whenever the dispatcher has debug information.
|
||||
* @event StreamDispatcher#debug
|
||||
* @param {string} info The debug info
|
||||
*/
|
||||
this._setSpeaking(1);
|
||||
if (!this.player.voiceConnection.sockets.udp) {
|
||||
this.emit('debug', 'Failed to send a packet - no UDP socket');
|
||||
return;
|
||||
}
|
||||
this.player.voiceConnection.sockets.udp.send(packet).catch(e => {
|
||||
this._setSpeaking(0);
|
||||
this.emit('debug', `Failed to send a packet - ${e}`);
|
||||
});
|
||||
}
|
||||
|
||||
_setSpeaking(value) {
|
||||
if (typeof this.player.voiceConnection !== 'undefined') {
|
||||
this.player.voiceConnection.setSpeaking(value);
|
||||
}
|
||||
/**
|
||||
* Emitted when the dispatcher starts/stops speaking.
|
||||
* @event StreamDispatcher#speaking
|
||||
* @param {boolean} value Whether or not the dispatcher is speaking
|
||||
*/
|
||||
this.emit('speaking', value);
|
||||
}
|
||||
|
||||
get volumeEditable() {
|
||||
return Boolean(this.streams.volume);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the Opus bitrate of this stream is editable
|
||||
* @type {boolean}
|
||||
* @readonly
|
||||
*/
|
||||
get bitrateEditable() {
|
||||
return this.streams.opus && this.streams.opus.setBitrate;
|
||||
}
|
||||
|
||||
// Volume
|
||||
get volume() {
|
||||
return this.streams.volume ? this.streams.volume.volume : 1;
|
||||
}
|
||||
|
||||
setVolume(value) {
|
||||
if (!this.streams.volume) return false;
|
||||
/**
|
||||
* Emitted when the volume of this dispatcher changes.
|
||||
* @event StreamDispatcher#volumeChange
|
||||
* @param {number} oldVolume The old volume of this dispatcher
|
||||
* @param {number} newVolume The new volume of this dispatcher
|
||||
*/
|
||||
this.emit('volumeChange', this.volume, value);
|
||||
this.streams.volume.setVolume(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Volume stubs for docs
|
||||
/* eslint-disable no-empty-function*/
|
||||
get volumeDecibels() {}
|
||||
get volumeLogarithmic() {}
|
||||
setVolumeDecibels() {}
|
||||
setVolumeLogarithmic() {}
|
||||
}
|
||||
|
||||
VolumeInterface.applyToClass(StreamDispatcher);
|
||||
|
||||
module.exports = StreamDispatcher;
|
||||
@@ -1,154 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const udp = require('dgram');
|
||||
const EventEmitter = require('events');
|
||||
const { Error } = require('../../../errors');
|
||||
const { VoiceOPCodes } = require('../../../util/Constants');
|
||||
|
||||
/**
|
||||
* Represents a UDP client for a Voice Connection.
|
||||
* @extends {EventEmitter}
|
||||
* @private
|
||||
*/
|
||||
class VoiceConnectionUDPClient extends EventEmitter {
|
||||
constructor(voiceConnection) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The voice connection that this UDP client serves
|
||||
* @type {VoiceConnection}
|
||||
*/
|
||||
this.voiceConnection = voiceConnection;
|
||||
|
||||
/**
|
||||
* The UDP socket
|
||||
* @type {?Socket}
|
||||
*/
|
||||
this.socket = null;
|
||||
|
||||
/**
|
||||
* The address of the Discord voice server
|
||||
* @type {?string}
|
||||
*/
|
||||
this.discordAddress = null;
|
||||
|
||||
/**
|
||||
* The local IP address
|
||||
* @type {?string}
|
||||
*/
|
||||
this.localAddress = null;
|
||||
|
||||
/**
|
||||
* The local port
|
||||
* @type {?string}
|
||||
*/
|
||||
this.localPort = null;
|
||||
|
||||
this.voiceConnection.on('closing', this.shutdown.bind(this));
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
this.emit('debug', `[UDP] shutdown requested`);
|
||||
if (this.socket) {
|
||||
this.socket.removeAllListeners('message');
|
||||
try {
|
||||
this.socket.close();
|
||||
} finally {
|
||||
this.socket = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The port of the Discord voice server
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
get discordPort() {
|
||||
return this.voiceConnection.authentication.port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet to the UDP client.
|
||||
* @param {Object} packet The packet to send
|
||||
* @returns {Promise<Object>}
|
||||
*/
|
||||
send(packet) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.socket) throw new Error('UDP_SEND_FAIL');
|
||||
if (!this.discordAddress || !this.discordPort) throw new Error('UDP_ADDRESS_MALFORMED');
|
||||
this.socket.send(packet, 0, packet.length, this.discordPort, this.discordAddress, error => {
|
||||
if (error) {
|
||||
this.emit('debug', `[UDP] >> ERROR: ${error}`);
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(packet);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async createUDPSocket(address) {
|
||||
this.discordAddress = address;
|
||||
const socket = (this.socket = udp.createSocket('udp4'));
|
||||
socket.on('error', e => {
|
||||
this.emit('debug', `[UDP] Error: ${e}`);
|
||||
this.emit('error', e);
|
||||
});
|
||||
socket.on('close', () => {
|
||||
this.emit('debug', '[UDP] socket closed');
|
||||
});
|
||||
this.emit('debug', `[UDP] created socket`);
|
||||
socket.once('message', message => {
|
||||
this.emit('debug', `[UDP] message: [${[...message]}] (${message})`);
|
||||
// Stop if the sockets have been deleted because the connection has been closed already
|
||||
if (!this.voiceConnection.sockets.ws) return;
|
||||
|
||||
const packet = parseLocalPacket(message);
|
||||
if (packet.error) {
|
||||
this.emit('debug', `[UDP] ERROR: ${packet.error}`);
|
||||
this.emit('error', packet.error);
|
||||
return;
|
||||
}
|
||||
|
||||
this.localAddress = packet.address;
|
||||
this.localPort = packet.port;
|
||||
|
||||
this.voiceConnection.sockets.ws.sendPacket({
|
||||
op: VoiceOPCodes.SELECT_PROTOCOL,
|
||||
d: {
|
||||
protocol: 'udp',
|
||||
data: {
|
||||
address: packet.address,
|
||||
port: packet.port,
|
||||
mode: this.voiceConnection.authentication.mode,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
this.emit('debug', `[UDP] << ${JSON.stringify(packet)}`);
|
||||
|
||||
socket.on('message', buffer => this.voiceConnection.receiver.packets.push(buffer));
|
||||
});
|
||||
|
||||
const blankMessage = Buffer.alloc(70);
|
||||
blankMessage.writeUIntBE(this.voiceConnection.authentication.ssrc, 0, 4);
|
||||
this.emit('debug', `Sending IP discovery packet: [${[...blankMessage]}]`);
|
||||
await this.send(blankMessage);
|
||||
this.emit('debug', `Successfully sent IP discovery packet`);
|
||||
}
|
||||
}
|
||||
|
||||
function parseLocalPacket(message) {
|
||||
try {
|
||||
const packet = Buffer.from(message);
|
||||
let address = '';
|
||||
for (let i = 4; i < packet.indexOf(0, i); i++) address += String.fromCharCode(packet[i]);
|
||||
const port = parseInt(packet.readUIntLE(packet.length - 2, 2).toString(10), 10);
|
||||
return { address, port };
|
||||
} catch (error) {
|
||||
return { error };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VoiceConnectionUDPClient;
|
||||
@@ -1,264 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const WebSocket = require('../../../WebSocket');
|
||||
const { Error } = require('../../../errors');
|
||||
const { OPCodes, VoiceOPCodes } = require('../../../util/Constants');
|
||||
|
||||
/**
|
||||
* Represents a Voice Connection's WebSocket.
|
||||
* @extends {EventEmitter}
|
||||
* @private
|
||||
*/
|
||||
class VoiceWebSocket extends EventEmitter {
|
||||
constructor(connection) {
|
||||
super();
|
||||
/**
|
||||
* The Voice Connection that this WebSocket serves
|
||||
* @type {VoiceConnection}
|
||||
*/
|
||||
this.connection = connection;
|
||||
|
||||
/**
|
||||
* How many connection attempts have been made
|
||||
* @type {number}
|
||||
*/
|
||||
this.attempts = 0;
|
||||
|
||||
this.dead = false;
|
||||
this.connection.on('closing', this.shutdown.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* The client of this voice WebSocket
|
||||
* @type {Client}
|
||||
* @readonly
|
||||
*/
|
||||
get client() {
|
||||
return this.connection.client;
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
this.emit('debug', `[WS] shutdown requested`);
|
||||
this.dead = true;
|
||||
this.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the current WebSocket.
|
||||
*/
|
||||
reset() {
|
||||
this.emit('debug', `[WS] reset requested`);
|
||||
if (this.ws) {
|
||||
if (this.ws.readyState !== WebSocket.CLOSED) this.ws.close();
|
||||
this.ws = null;
|
||||
}
|
||||
this.clearHeartbeat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts connecting to the Voice WebSocket Server.
|
||||
*/
|
||||
connect() {
|
||||
this.emit('debug', `[WS] connect requested`);
|
||||
if (this.dead) return;
|
||||
if (this.ws) this.reset();
|
||||
if (this.attempts >= 5) {
|
||||
this.emit('debug', new Error('VOICE_CONNECTION_ATTEMPTS_EXCEEDED', this.attempts));
|
||||
return;
|
||||
}
|
||||
|
||||
this.attempts++;
|
||||
|
||||
/**
|
||||
* The actual WebSocket used to connect to the Voice WebSocket Server.
|
||||
* @type {WebSocket}
|
||||
*/
|
||||
this.ws = WebSocket.create(`wss://${this.connection.authentication.endpoint}/`, { v: 4 });
|
||||
this.emit('debug', `[WS] connecting, ${this.attempts} attempts, ${this.ws.url}`);
|
||||
this.ws.onopen = this.onOpen.bind(this);
|
||||
this.ws.onmessage = this.onMessage.bind(this);
|
||||
this.ws.onclose = this.onClose.bind(this);
|
||||
this.ws.onerror = this.onError.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends data to the WebSocket if it is open.
|
||||
* @param {string} data The data to send to the WebSocket
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
send(data) {
|
||||
this.emit('debug', `[WS] >> ${data}`);
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) throw new Error('WS_NOT_OPEN', data);
|
||||
this.ws.send(data, null, error => {
|
||||
if (error) reject(error);
|
||||
else resolve(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON.stringify's a packet and then sends it to the WebSocket Server.
|
||||
* @param {Object} packet The packet to send
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
sendPacket(packet) {
|
||||
try {
|
||||
packet = JSON.stringify(packet);
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
return this.send(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever the WebSocket opens.
|
||||
*/
|
||||
onOpen() {
|
||||
this.emit('debug', `[WS] opened at gateway ${this.connection.authentication.endpoint}`);
|
||||
this.sendPacket({
|
||||
op: OPCodes.DISPATCH,
|
||||
d: {
|
||||
server_id: this.connection.channel.guild.id,
|
||||
user_id: this.client.user.id,
|
||||
token: this.connection.authentication.token,
|
||||
session_id: this.connection.authentication.sessionID,
|
||||
},
|
||||
}).catch(() => {
|
||||
this.emit('error', new Error('VOICE_JOIN_SOCKET_CLOSED'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a message is received from the WebSocket.
|
||||
* @param {MessageEvent} event The message event that was received
|
||||
* @returns {void}
|
||||
*/
|
||||
onMessage(event) {
|
||||
try {
|
||||
return this.onPacket(WebSocket.unpack(event.data, 'json'));
|
||||
} catch (error) {
|
||||
return this.onError(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever the connection to the WebSocket server is lost.
|
||||
*/
|
||||
onClose() {
|
||||
this.emit('debug', `[WS] closed`);
|
||||
if (!this.dead) this.client.setTimeout(this.connect.bind(this), this.attempts * 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever an error occurs with the WebSocket.
|
||||
* @param {Error} error The error that occurred
|
||||
*/
|
||||
onError(error) {
|
||||
this.emit('debug', `[WS] Error: ${error}`);
|
||||
this.emit('error', error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever a valid packet is received from the WebSocket.
|
||||
* @param {Object} packet The received packet
|
||||
*/
|
||||
onPacket(packet) {
|
||||
this.emit('debug', `[WS] << ${JSON.stringify(packet)}`);
|
||||
switch (packet.op) {
|
||||
case VoiceOPCodes.HELLO:
|
||||
this.setHeartbeat(packet.d.heartbeat_interval);
|
||||
break;
|
||||
case VoiceOPCodes.READY:
|
||||
/**
|
||||
* Emitted once the voice WebSocket receives the ready packet.
|
||||
* @param {Object} packet The received packet
|
||||
* @event VoiceWebSocket#ready
|
||||
*/
|
||||
this.emit('ready', packet.d);
|
||||
break;
|
||||
/* eslint-disable no-case-declarations */
|
||||
case VoiceOPCodes.SESSION_DESCRIPTION:
|
||||
packet.d.secret_key = new Uint8Array(packet.d.secret_key);
|
||||
/**
|
||||
* Emitted once the Voice Websocket receives a description of this voice session.
|
||||
* @param {Object} packet The received packet
|
||||
* @event VoiceWebSocket#sessionDescription
|
||||
*/
|
||||
this.emit('sessionDescription', packet.d);
|
||||
break;
|
||||
case VoiceOPCodes.CLIENT_CONNECT:
|
||||
this.connection.ssrcMap.set(+packet.d.audio_ssrc, packet.d.user_id);
|
||||
break;
|
||||
case VoiceOPCodes.CLIENT_DISCONNECT:
|
||||
const streamInfo = this.connection.receiver && this.connection.receiver.packets.streams.get(packet.d.user_id);
|
||||
if (streamInfo) {
|
||||
this.connection.receiver.packets.streams.delete(packet.d.user_id);
|
||||
streamInfo.stream.push(null);
|
||||
}
|
||||
break;
|
||||
case VoiceOPCodes.SPEAKING:
|
||||
/**
|
||||
* Emitted whenever a speaking packet is received.
|
||||
* @param {Object} data
|
||||
* @event VoiceWebSocket#startSpeaking
|
||||
*/
|
||||
this.emit('startSpeaking', packet.d);
|
||||
break;
|
||||
default:
|
||||
/**
|
||||
* Emitted when an unhandled packet is received.
|
||||
* @param {Object} packet
|
||||
* @event VoiceWebSocket#unknownPacket
|
||||
*/
|
||||
this.emit('unknownPacket', packet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an interval at which to send a heartbeat packet to the WebSocket.
|
||||
* @param {number} interval The interval at which to send a heartbeat packet
|
||||
*/
|
||||
setHeartbeat(interval) {
|
||||
if (!interval || isNaN(interval)) {
|
||||
this.onError(new Error('VOICE_INVALID_HEARTBEAT'));
|
||||
return;
|
||||
}
|
||||
if (this.heartbeatInterval) {
|
||||
/**
|
||||
* Emitted whenever the voice WebSocket encounters a non-fatal error.
|
||||
* @param {string} warn The warning
|
||||
* @event VoiceWebSocket#warn
|
||||
*/
|
||||
this.emit('warn', 'A voice heartbeat interval is being overwritten');
|
||||
this.client.clearInterval(this.heartbeatInterval);
|
||||
}
|
||||
this.heartbeatInterval = this.client.setInterval(this.sendHeartbeat.bind(this), interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears a heartbeat interval, if one exists.
|
||||
*/
|
||||
clearHeartbeat() {
|
||||
if (!this.heartbeatInterval) {
|
||||
this.emit('warn', 'Tried to clear a heartbeat interval that does not exist');
|
||||
return;
|
||||
}
|
||||
this.client.clearInterval(this.heartbeatInterval);
|
||||
this.heartbeatInterval = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a heartbeat packet.
|
||||
*/
|
||||
sendHeartbeat() {
|
||||
this.sendPacket({ op: VoiceOPCodes.HEARTBEAT, d: Math.floor(Math.random() * 10e10) }).catch(() => {
|
||||
this.emit('warn', 'Tried to send heartbeat, but connection is not open');
|
||||
this.clearHeartbeat();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VoiceWebSocket;
|
||||
@@ -1,27 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const BasePlayer = require('./BasePlayer');
|
||||
|
||||
/**
|
||||
* An Audio Player for a Voice Connection.
|
||||
* @private
|
||||
* @extends {BasePlayer}
|
||||
*/
|
||||
class AudioPlayer extends BasePlayer {
|
||||
constructor(voiceConnection) {
|
||||
super();
|
||||
/**
|
||||
* The voice connection that the player serves
|
||||
* @type {VoiceConnection}
|
||||
*/
|
||||
this.voiceConnection = voiceConnection;
|
||||
}
|
||||
|
||||
playBroadcast(broadcast, options) {
|
||||
const dispatcher = this.createDispatcher(options, { broadcast });
|
||||
broadcast.add(dispatcher);
|
||||
return dispatcher;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AudioPlayer;
|
||||
@@ -1,92 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const { Readable: ReadableStream } = require('stream');
|
||||
const prism = require('prism-media');
|
||||
const StreamDispatcher = require('../dispatcher/StreamDispatcher');
|
||||
|
||||
const FFMPEG_ARGUMENTS = ['-analyzeduration', '0', '-loglevel', '0', '-f', 's16le', '-ar', '48000', '-ac', '2'];
|
||||
|
||||
/**
|
||||
* An Audio Player for a Voice Connection.
|
||||
* @private
|
||||
* @extends {EventEmitter}
|
||||
*/
|
||||
class BasePlayer extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.dispatcher = null;
|
||||
|
||||
this.streamingData = {
|
||||
channels: 2,
|
||||
sequence: 0,
|
||||
timestamp: 0,
|
||||
};
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.destroyDispatcher();
|
||||
}
|
||||
|
||||
destroyDispatcher() {
|
||||
if (this.dispatcher) {
|
||||
this.dispatcher.destroy();
|
||||
this.dispatcher = null;
|
||||
}
|
||||
}
|
||||
|
||||
playUnknown(input, options) {
|
||||
this.destroyDispatcher();
|
||||
|
||||
const isStream = input instanceof ReadableStream;
|
||||
|
||||
const args = isStream ? FFMPEG_ARGUMENTS.slice() : ['-i', input, ...FFMPEG_ARGUMENTS];
|
||||
if (options.seek) args.unshift('-ss', String(options.seek));
|
||||
|
||||
const ffmpeg = new prism.FFmpeg({ args });
|
||||
const streams = { ffmpeg };
|
||||
if (isStream) {
|
||||
streams.input = input;
|
||||
input.pipe(ffmpeg);
|
||||
}
|
||||
return this.playPCMStream(ffmpeg, options, streams);
|
||||
}
|
||||
|
||||
playPCMStream(stream, options, streams = {}) {
|
||||
this.destroyDispatcher();
|
||||
const opus = (streams.opus = new prism.opus.Encoder({ channels: 2, rate: 48000, frameSize: 960 }));
|
||||
if (options && options.volume === false) {
|
||||
stream.pipe(opus);
|
||||
return this.playOpusStream(opus, options, streams);
|
||||
}
|
||||
streams.volume = new prism.VolumeTransformer({ type: 's16le', volume: options ? options.volume : 1 });
|
||||
stream.pipe(streams.volume).pipe(opus);
|
||||
return this.playOpusStream(opus, options, streams);
|
||||
}
|
||||
|
||||
playOpusStream(stream, options, streams = {}) {
|
||||
this.destroyDispatcher();
|
||||
streams.opus = stream;
|
||||
if (options.volume !== false && !streams.input) {
|
||||
streams.input = stream;
|
||||
const decoder = new prism.opus.Decoder({ channels: 2, rate: 48000, frameSize: 960 });
|
||||
streams.volume = new prism.VolumeTransformer({ type: 's16le', volume: options ? options.volume : 1 });
|
||||
streams.opus = stream
|
||||
.pipe(decoder)
|
||||
.pipe(streams.volume)
|
||||
.pipe(new prism.opus.Encoder({ channels: 2, rate: 48000, frameSize: 960 }));
|
||||
}
|
||||
const dispatcher = this.createDispatcher(options, streams);
|
||||
streams.opus.pipe(dispatcher);
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
createDispatcher(options, streams, broadcast) {
|
||||
this.destroyDispatcher();
|
||||
const dispatcher = (this.dispatcher = new StreamDispatcher(this, options, streams, broadcast));
|
||||
return dispatcher;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BasePlayer;
|
||||
@@ -1,28 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const BasePlayer = require('./BasePlayer');
|
||||
const BroadcastDispatcher = require('../dispatcher/BroadcastDispatcher');
|
||||
|
||||
/**
|
||||
* An Audio Player for a Voice Connection.
|
||||
* @private
|
||||
* @extends {BasePlayer}
|
||||
*/
|
||||
class AudioPlayer extends BasePlayer {
|
||||
constructor(broadcast) {
|
||||
super();
|
||||
/**
|
||||
* The broadcast that the player serves
|
||||
* @type {VoiceBroadcast}
|
||||
*/
|
||||
this.broadcast = broadcast;
|
||||
}
|
||||
|
||||
createDispatcher(options, streams) {
|
||||
this.destroyDispatcher();
|
||||
const dispatcher = (this.dispatcher = new BroadcastDispatcher(this, options, streams));
|
||||
return dispatcher;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AudioPlayer;
|
||||
@@ -1,116 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const secretbox = require('../util/Secretbox');
|
||||
|
||||
// The delay between packets when a user is considered to have stopped speaking
|
||||
// https://github.com/discordjs/discord.js/issues/3524#issuecomment-540373200
|
||||
const DISCORD_SPEAKING_DELAY = 250;
|
||||
|
||||
class Readable extends require('stream').Readable {
|
||||
_read() {} // eslint-disable-line no-empty-function
|
||||
}
|
||||
|
||||
class PacketHandler extends EventEmitter {
|
||||
constructor(receiver) {
|
||||
super();
|
||||
this.nonce = Buffer.alloc(24);
|
||||
this.receiver = receiver;
|
||||
this.streams = new Map();
|
||||
this.speakingTimeouts = new Map();
|
||||
}
|
||||
|
||||
get connection() {
|
||||
return this.receiver.connection;
|
||||
}
|
||||
|
||||
_stoppedSpeaking(userID) {
|
||||
const streamInfo = this.streams.get(userID);
|
||||
if (streamInfo && streamInfo.end === 'silence') {
|
||||
this.streams.delete(userID);
|
||||
streamInfo.stream.push(null);
|
||||
}
|
||||
}
|
||||
|
||||
makeStream(user, end) {
|
||||
if (this.streams.has(user)) return this.streams.get(user).stream;
|
||||
const stream = new Readable();
|
||||
stream.on('end', () => this.streams.delete(user));
|
||||
this.streams.set(user, { stream, end });
|
||||
return stream;
|
||||
}
|
||||
|
||||
parseBuffer(buffer) {
|
||||
const { secret_key, mode } = this.receiver.connection.authentication;
|
||||
|
||||
// Choose correct nonce depending on encryption
|
||||
let end;
|
||||
if (mode === 'xsalsa20_poly1305_lite') {
|
||||
buffer.copy(this.nonce, 0, buffer.length - 4);
|
||||
end = buffer.length - 4;
|
||||
} else if (mode === 'xsalsa20_poly1305_suffix') {
|
||||
buffer.copy(this.nonce, 0, buffer.length - 24);
|
||||
end = buffer.length - 24;
|
||||
} else {
|
||||
buffer.copy(this.nonce, 0, 0, 12);
|
||||
}
|
||||
|
||||
// Open packet
|
||||
let packet = secretbox.methods.open(buffer.slice(12, end), this.nonce, secret_key);
|
||||
if (!packet) return new Error('Failed to decrypt voice packet');
|
||||
packet = Buffer.from(packet);
|
||||
|
||||
// Strip RTP Header Extensions (one-byte only)
|
||||
if (packet[0] === 0xbe && packet[1] === 0xde && packet.length > 4) {
|
||||
const headerExtensionLength = packet.readUInt16BE(2);
|
||||
let offset = 4;
|
||||
for (let i = 0; i < headerExtensionLength; i++) {
|
||||
const byte = packet[offset];
|
||||
offset++;
|
||||
if (byte === 0) continue;
|
||||
offset += 1 + (0b1111 & (byte >> 4));
|
||||
}
|
||||
// Skip over undocumented Discord byte
|
||||
offset++;
|
||||
|
||||
packet = packet.slice(offset);
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
push(buffer) {
|
||||
const ssrc = buffer.readUInt32BE(8);
|
||||
const userStat = this.connection.ssrcMap.get(ssrc);
|
||||
if (!userStat) return;
|
||||
|
||||
let speakingTimeout = this.speakingTimeouts.get(ssrc);
|
||||
if (typeof speakingTimeout === 'undefined') {
|
||||
this.connection.onSpeaking({ user_id: userStat.userID, ssrc: ssrc, speaking: userStat.speaking });
|
||||
speakingTimeout = this.receiver.connection.client.setTimeout(() => {
|
||||
try {
|
||||
this.connection.onSpeaking({ user_id: userStat.userID, ssrc: ssrc, speaking: 0 });
|
||||
this.receiver.connection.client.clearTimeout(speakingTimeout);
|
||||
this.speakingTimeouts.delete(ssrc);
|
||||
} catch {
|
||||
// Connection already closed, ignore
|
||||
}
|
||||
}, DISCORD_SPEAKING_DELAY);
|
||||
this.speakingTimeouts.set(ssrc, speakingTimeout);
|
||||
} else {
|
||||
speakingTimeout.refresh();
|
||||
}
|
||||
|
||||
let stream = this.streams.get(userStat.userID);
|
||||
if (!stream) return;
|
||||
stream = stream.stream;
|
||||
const opusPacket = this.parseBuffer(buffer);
|
||||
if (opusPacket instanceof Error) {
|
||||
this.emit('error', opusPacket);
|
||||
return;
|
||||
}
|
||||
stream.push(opusPacket);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PacketHandler;
|
||||
@@ -1,58 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
const prism = require('prism-media');
|
||||
const PacketHandler = require('./PacketHandler');
|
||||
const { Error } = require('../../../errors');
|
||||
|
||||
/**
|
||||
* Receives audio packets from a voice connection.
|
||||
* @example
|
||||
* const receiver = connection.createReceiver();
|
||||
* // opusStream is a ReadableStream - that means you could play it back to a voice channel if you wanted to!
|
||||
* const opusStream = receiver.createStream(user);
|
||||
*/
|
||||
class VoiceReceiver extends EventEmitter {
|
||||
constructor(connection) {
|
||||
super();
|
||||
this.connection = connection;
|
||||
this.packets = new PacketHandler(this);
|
||||
/**
|
||||
* Emitted whenever there is a warning
|
||||
* @event VoiceReceiver#debug
|
||||
* @param {Error|string} error The error or message to debug
|
||||
*/
|
||||
this.packets.on('error', err => this.emit('debug', err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Options passed to `VoiceReceiver#createStream`.
|
||||
* @typedef {Object} ReceiveStreamOptions
|
||||
* @property {string} [mode='opus'] The mode for audio output. This defaults to opus, meaning discord.js won't decode
|
||||
* the packets for you. You can set this to 'pcm' so that the stream's output will be 16-bit little-endian stereo
|
||||
* audio
|
||||
* @property {string} [end='silence'] When the stream should be destroyed. If `silence`, this will be when the user
|
||||
* stops talking. Otherwise, if `manual`, this should be handled by you.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a new audio receiving stream. If a stream already exists for a user, then that stream will be returned
|
||||
* rather than generating a new one.
|
||||
* @param {UserResolvable} user The user to start listening to.
|
||||
* @param {ReceiveStreamOptions} options Options.
|
||||
* @returns {ReadableStream}
|
||||
*/
|
||||
createStream(user, { mode = 'opus', end = 'silence' } = {}) {
|
||||
user = this.connection.client.users.resolve(user);
|
||||
if (!user) throw new Error('VOICE_USER_MISSING');
|
||||
const stream = this.packets.makeStream(user.id, end);
|
||||
if (mode === 'pcm') {
|
||||
const decoder = new prism.opus.Decoder({ channels: 2, rate: 48000, frameSize: 960 });
|
||||
stream.pipe(decoder);
|
||||
return decoder;
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = VoiceReceiver;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user