mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-23 03:50:09 +00:00
Compare commits
977 Commits
v12
...
@discordjs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16390efe6e | ||
|
|
780b7ed39f | ||
|
|
9cdc4482a0 | ||
|
|
2f6f365098 | ||
|
|
22cadaf40f | ||
|
|
3496516dc9 | ||
|
|
baacd6ba69 | ||
|
|
1391c363e5 | ||
|
|
4cc6331e5c | ||
|
|
1ae1853788 | ||
|
|
d80fddf06d | ||
|
|
3c62bd2d47 | ||
|
|
d0c3961aef | ||
|
|
fc4292e2e9 | ||
|
|
7e5f16b6b3 | ||
|
|
f1d35e32ee | ||
|
|
2bfc638a5c | ||
|
|
ea9e897b92 | ||
|
|
bf346e7fdf | ||
|
|
391211040a | ||
|
|
1626dded5b | ||
|
|
e6f41b578a | ||
|
|
1316fd4c6a | ||
|
|
aa7c1b2081 | ||
|
|
2ed02f7fc7 | ||
|
|
a0a5b0e4fa | ||
|
|
b763dabaa9 | ||
|
|
7b65a04cb1 | ||
|
|
6bb03f2c34 | ||
|
|
645b3f84f4 | ||
|
|
77489b90fc | ||
|
|
b9b60a37b3 | ||
|
|
55960cc778 | ||
|
|
8efc5c7b8d | ||
|
|
d1ef2f5e8b | ||
|
|
bc6a6c539f | ||
|
|
a0fe0acbf1 | ||
|
|
d43f68488e | ||
|
|
1e00fc2001 | ||
|
|
49f9a18020 | ||
|
|
9cf44d1c0e | ||
|
|
2ce244b502 | ||
|
|
717e0e963f | ||
|
|
ee91f5a19c | ||
|
|
5a5c045534 | ||
|
|
de61fe4854 | ||
|
|
6e57b65e99 | ||
|
|
25b8491235 | ||
|
|
23513d1917 | ||
|
|
fdba146f9b | ||
|
|
4515bb1ab2 | ||
|
|
1230bee9bc | ||
|
|
b0937502d3 | ||
|
|
f410536c51 | ||
|
|
6f58e8122d | ||
|
|
5ec542d61f | ||
|
|
7f980e38b6 | ||
|
|
b5cd2884b6 | ||
|
|
f028aea333 | ||
|
|
3846f0d97c | ||
|
|
b6b4570482 | ||
|
|
8b200c0fee | ||
|
|
1c93faa3ab | ||
|
|
01f8d1bed5 | ||
|
|
5fcda73d9f | ||
|
|
552d89fd4e | ||
|
|
b183a8eece | ||
|
|
da86bd4fa3 | ||
|
|
c07207f219 | ||
|
|
4fe063f0d0 | ||
|
|
a39d8c4d9d | ||
|
|
85e6812ce2 | ||
|
|
e305156769 | ||
|
|
374f970efe | ||
|
|
e59fac3fe3 | ||
|
|
fd63139b41 | ||
|
|
0193efae71 | ||
|
|
fabd34381c | ||
|
|
2c91c488e8 | ||
|
|
54f937d82c | ||
|
|
9f3bf2927c | ||
|
|
2a0dedf3e9 | ||
|
|
7efeff461f | ||
|
|
099536ee60 | ||
|
|
77aff08345 | ||
|
|
c1f2fe29ef | ||
|
|
a1a8ca4814 | ||
|
|
48555cb8eb | ||
|
|
802a5ac228 | ||
|
|
db09d79423 | ||
|
|
0c5c7210e7 | ||
|
|
493e4f9350 | ||
|
|
c0ba2d46d0 | ||
|
|
fdb09cbe03 | ||
|
|
ecc61f3c74 | ||
|
|
06cd16fe97 | ||
|
|
73854ee852 | ||
|
|
5e0a7d51fc | ||
|
|
7630158f59 | ||
|
|
9f240ea0d1 | ||
|
|
b001e194f1 | ||
|
|
8e881d2b96 | ||
|
|
c30a818ca9 | ||
|
|
3c857a6363 | ||
|
|
b256ae1fa6 | ||
|
|
49e3ce2133 | ||
|
|
c297829d54 | ||
|
|
dc6454104f | ||
|
|
28688e27d5 | ||
|
|
f43140abac | ||
|
|
47d74ebf81 | ||
|
|
e94073a6ab | ||
|
|
076524a064 | ||
|
|
5ec04e077b | ||
|
|
9bd3689fb1 | ||
|
|
95d2a4d35e | ||
|
|
bb245b7b35 | ||
|
|
204aee799a | ||
|
|
2d9ffb8c5b | ||
|
|
b6484ac117 | ||
|
|
761a901885 | ||
|
|
0238da45c5 | ||
|
|
27fb5e5c6b | ||
|
|
673c03f7cf | ||
|
|
d6685b1c50 | ||
|
|
14716df6b6 | ||
|
|
aa4d05504f | ||
|
|
7be9170659 | ||
|
|
5d987ee56e | ||
|
|
49e686a721 | ||
|
|
ddf759c811 | ||
|
|
14d9a9901b | ||
|
|
ee93a27e15 | ||
|
|
91a432e49d | ||
|
|
c278674e8a | ||
|
|
aa532946c9 | ||
|
|
bdd841a1e7 | ||
|
|
fae4abf2f7 | ||
|
|
b2836daafe | ||
|
|
f169c8fe46 | ||
|
|
740d3f006e | ||
|
|
88060395d1 | ||
|
|
acbfc5c866 | ||
|
|
e12a5b6a0c | ||
|
|
b27888455f | ||
|
|
76856b967a | ||
|
|
ceaf738d2e | ||
|
|
b6c9fd691f | ||
|
|
7621e9da4c | ||
|
|
672baa49e6 | ||
|
|
c3948f8253 | ||
|
|
579569ae18 | ||
|
|
399e720b92 | ||
|
|
e0afcadda4 | ||
|
|
4dff279a6f | ||
|
|
487d32d303 | ||
|
|
7513b4528c | ||
|
|
e8b69974dc | ||
|
|
d27fddbf9a | ||
|
|
d193d04cea | ||
|
|
ef01b84fa8 | ||
|
|
f7b7aac8b6 | ||
|
|
267a4b3f68 | ||
|
|
38cc89e5ae | ||
|
|
12ab5c8878 | ||
|
|
c44ea50157 | ||
|
|
046f44b807 | ||
|
|
4354c37762 | ||
|
|
b541d0a524 | ||
|
|
6898fa3b37 | ||
|
|
460df9eb4d | ||
|
|
bd48e6df84 | ||
|
|
5566404850 | ||
|
|
29667c96e5 | ||
|
|
b47467755c | ||
|
|
187581dd84 | ||
|
|
b030130df1 | ||
|
|
d57ec7ab68 | ||
|
|
b1b9c83df0 | ||
|
|
bfb89de864 | ||
|
|
26f927b9fe | ||
|
|
0d599a1a76 | ||
|
|
e24209a8b1 | ||
|
|
d399a28323 | ||
|
|
872e7a59b2 | ||
|
|
78124aed28 | ||
|
|
b1656bfb4f | ||
|
|
03c4b60384 | ||
|
|
45ebea3216 | ||
|
|
a84e51b767 | ||
|
|
e31c5ca1a8 | ||
|
|
d32956c6b7 | ||
|
|
adc850aa67 | ||
|
|
26340acad9 | ||
|
|
8bc1ece98e | ||
|
|
ba93e85d0d | ||
|
|
d0025beb7b | ||
|
|
c5421af68e | ||
|
|
a194d9c37f | ||
|
|
d873a19d34 | ||
|
|
f88f4cca64 | ||
|
|
00e1e2673b | ||
|
|
1db3e76054 | ||
|
|
7eec06145a | ||
|
|
c3f4de4801 | ||
|
|
42acc6eef9 | ||
|
|
32b5c2e617 | ||
|
|
abf158dc94 | ||
|
|
7129965423 | ||
|
|
a8c21cd754 | ||
|
|
6e5c768379 | ||
|
|
d15dd5f07d | ||
|
|
905d100d4d | ||
|
|
34b2ad0d8e | ||
|
|
a8e60105fb | ||
|
|
9e421f6ccf | ||
|
|
28d96e344b | ||
|
|
3eacf7a587 | ||
|
|
e9daa31eaf | ||
|
|
9eb9591473 | ||
|
|
8b4456e0aa | ||
|
|
b76bb8a409 | ||
|
|
107822d28d | ||
|
|
cdf65f74e1 | ||
|
|
a7cb314e07 | ||
|
|
3a978f347c | ||
|
|
10478ad148 | ||
|
|
7c4d1dffb4 | ||
|
|
2803db683d | ||
|
|
3f1100976f | ||
|
|
531b46c60d | ||
|
|
466e796a1d | ||
|
|
8d80fec86d | ||
|
|
fe9500538e | ||
|
|
da3ae4854e | ||
|
|
dfd7b403a9 | ||
|
|
7cba67620e | ||
|
|
c5db0ff606 | ||
|
|
60aa9ae478 | ||
|
|
3b14883e34 | ||
|
|
8426770865 | ||
|
|
79b1b20562 | ||
|
|
60b8ba6b86 | ||
|
|
d3da83368d | ||
|
|
f8aa4bd470 | ||
|
|
a06a87a7c4 | ||
|
|
1ca8d2c8e8 | ||
|
|
42fdcaa1da | ||
|
|
94ca0f599d | ||
|
|
839974ca43 | ||
|
|
5070d23914 | ||
|
|
ecd637f7d6 | ||
|
|
66a90d3f89 | ||
|
|
caa3b60c30 | ||
|
|
29dd319b68 | ||
|
|
124e177e91 | ||
|
|
034782641a | ||
|
|
b9a4899491 | ||
|
|
5d87398f9f | ||
|
|
603350645d | ||
|
|
92f6471e8e | ||
|
|
88e2622dde | ||
|
|
75d85f7838 | ||
|
|
8add4b08f5 | ||
|
|
0a71a4d18f | ||
|
|
183dbd7e53 | ||
|
|
256fb905fe | ||
|
|
3c3522ae8a | ||
|
|
be8912a421 | ||
|
|
1b016a30c8 | ||
|
|
3183b1166a | ||
|
|
f866512e84 | ||
|
|
8cc3885739 | ||
|
|
c62823e43d | ||
|
|
ea3695585d | ||
|
|
ea6a57e927 | ||
|
|
f57791c5fe | ||
|
|
8826e9ffbc | ||
|
|
db73cf9255 | ||
|
|
08edc0b1db | ||
|
|
00bd92a451 | ||
|
|
d81590d566 | ||
|
|
06460565e4 | ||
|
|
08419561ed | ||
|
|
d16ada9708 | ||
|
|
cdb00053de | ||
|
|
2c219cb982 | ||
|
|
581921f8b7 | ||
|
|
f49f70a4eb | ||
|
|
54b33dd7df | ||
|
|
33f6f8211f | ||
|
|
29d5fd163c | ||
|
|
34024f5ef6 | ||
|
|
9301c9b420 | ||
|
|
03d5549461 | ||
|
|
774e9609d2 | ||
|
|
a6932546e2 | ||
|
|
0fe5f88316 | ||
|
|
b89280a1dd | ||
|
|
fc51f61f0c | ||
|
|
49e3a14d30 | ||
|
|
7d4a40a26d | ||
|
|
8a8c69a257 | ||
|
|
839c6da03d | ||
|
|
96e26c428d | ||
|
|
5c276398d6 | ||
|
|
705c5a1c17 | ||
|
|
4bfd5d3e74 | ||
|
|
8a95211230 | ||
|
|
141864917a | ||
|
|
57b94b9adf | ||
|
|
9ca10cce06 | ||
|
|
fb50dd9841 | ||
|
|
7aff15a055 | ||
|
|
c232baa715 | ||
|
|
656b51875f | ||
|
|
c14e594d8a | ||
|
|
21983de3e0 | ||
|
|
f39b597e31 | ||
|
|
70cc0295f8 | ||
|
|
d6e6244336 | ||
|
|
93a83c2cf7 | ||
|
|
17b407935b | ||
|
|
6cac03a394 | ||
|
|
76cf52cd0d | ||
|
|
a4b8623b60 | ||
|
|
5eb3553fd1 | ||
|
|
16493e65fd | ||
|
|
f294d1eff2 | ||
|
|
9a833b1e0e | ||
|
|
d289d5ccb7 | ||
|
|
2c449b6b48 | ||
|
|
81bb68d3be | ||
|
|
170c0c4985 | ||
|
|
ecb6e50b46 | ||
|
|
0109ad0466 | ||
|
|
84bb4f4153 | ||
|
|
71fdf6fae0 | ||
|
|
759faa4174 | ||
|
|
615afab8bb | ||
|
|
f1d5ffce04 | ||
|
|
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 |
10
.commitlintrc.json
Normal file
10
.commitlintrc.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": ["@commitlint/config-angular"],
|
||||
"rules": {
|
||||
"type-enum": [
|
||||
2,
|
||||
"always",
|
||||
["chore", "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test", "types", "typings"]
|
||||
]
|
||||
}
|
||||
}
|
||||
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 make 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 within all project spaces, and it also applies when
|
||||
an individual is representing the project or its community in public spaces.
|
||||
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
|
||||
91
.github/COMMIT_CONVENTION.md
vendored
Normal file
91
.github/COMMIT_CONVENTION.md
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
## Git Commit Message Convention
|
||||
|
||||
> This is adapted from [Angular's commit convention](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular).
|
||||
|
||||
#### TL;DR:
|
||||
|
||||
Messages must be matched by the following regex:
|
||||
|
||||
```js
|
||||
/^(revert: )?(feat|fix|docs|style|refactor|perf|test|workflow|build|ci|chore|types|wip)(\(.+\))?: .{1,72}/;
|
||||
```
|
||||
|
||||
#### Examples
|
||||
|
||||
Appears under "Features" header, `GuildMember` subheader:
|
||||
|
||||
```
|
||||
feat(GuildMember): add 'tag' method
|
||||
```
|
||||
|
||||
Appears under "Bug Fixes" header, `Guild` subheader, with a link to issue #28:
|
||||
|
||||
```
|
||||
fix(Guild): handle events correctly
|
||||
|
||||
close #28
|
||||
```
|
||||
|
||||
Appears under "Performance Improvements" header, and under "Breaking Changes" with the breaking change explanation:
|
||||
|
||||
```
|
||||
perf(core): improve patching by removing 'bar' option
|
||||
|
||||
BREAKING CHANGE: The 'bar' option has been removed.
|
||||
```
|
||||
|
||||
The following commit and commit `667ecc1` do not appear in the changelog if they are under the same release. If not, the revert commit appears under the "Reverts" header.
|
||||
|
||||
```
|
||||
revert: feat(Managers): add Managers
|
||||
|
||||
This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
|
||||
```
|
||||
|
||||
### Full Message Format
|
||||
|
||||
A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**:
|
||||
|
||||
```
|
||||
<type>(<scope>): <subject>
|
||||
<BLANK LINE>
|
||||
<body>
|
||||
<BLANK LINE>
|
||||
<footer>
|
||||
```
|
||||
|
||||
The **header** is mandatory and the **scope** of the header is optional.
|
||||
|
||||
### Revert
|
||||
|
||||
If the commit reverts a previous commit, it should begin with `revert:`, followed by the header of the reverted commit. In the body, it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
|
||||
|
||||
### Type
|
||||
|
||||
If the prefix is `feat`, `fix` or `perf`, it will appear in the changelog. However, if there is any [BREAKING CHANGE](#footer), the commit will always appear in the changelog.
|
||||
|
||||
Other prefixes are up to your discretion. Suggested prefixes are `docs`, `chore`, `style`, `refactor`, and `test` for non-changelog related tasks.
|
||||
|
||||
### Scope
|
||||
|
||||
The scope could be anything specifying the place of the commit change. For example `GuildMember`, `Guild`, `Message`, `MessageEmbed` etc...
|
||||
|
||||
### Subject
|
||||
|
||||
The subject contains a succinct description of the change:
|
||||
|
||||
- use the imperative, present tense: "change" not "changed" nor "changes"
|
||||
- don't capitalize the first letter
|
||||
- no dot (.) at the end
|
||||
|
||||
### Body
|
||||
|
||||
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
|
||||
The body should include the motivation for the change and contrast this with previous behavior.
|
||||
|
||||
### Footer
|
||||
|
||||
The footer should contain any information about **Breaking Changes** and is also the place to
|
||||
reference GitHub issues that this commit **Closes**.
|
||||
|
||||
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.
|
||||
11
.github/CONTRIBUTING.md
vendored
11
.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
|
||||
1. Fork & clone the repository, and make sure you're on the **main** branch
|
||||
2. Run `npm ci`
|
||||
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) (Make sure you follow the [conventional commit format](https://github.com/discordjs/discord.js-next/blob/master/.github/COMMIT_CONVENTION.md))
|
||||
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/blob/main/.github/COMMIT_CONVENTION.md))
|
||||
|
||||
13
.github/FUNDING.yml
vendored
13
.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
|
||||
patreon: discordjs
|
||||
github: [iCrawl, amishshah, vladfrangu, kyranet]
|
||||
open_collective: discordjs
|
||||
|
||||
45
.github/ISSUE_TEMPLATE/bug_report.md
vendored
45
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,45 +0,0 @@
|
||||
---
|
||||
|
||||
name: Bug report
|
||||
about: Report incorrect or unexpected behaviour of discord.js
|
||||
title: ''
|
||||
labels: 's: unverified, type: bug'
|
||||
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.
|
||||
-->
|
||||
|
||||
**Please describe the problem you are having in as much detail as possible:**
|
||||
|
||||
**Include a reproducible code sample here, if possible:**
|
||||
|
||||
```js
|
||||
// Place your code here
|
||||
```
|
||||
|
||||
**Further details:**
|
||||
|
||||
- discord.js version:
|
||||
- Node.js version:
|
||||
- Operating system:
|
||||
- Priority this issue should have – please be realistic and elaborate if possible:
|
||||
|
||||
**Relevant client options:**
|
||||
|
||||
- partials: none
|
||||
- gateway intents: none
|
||||
- other: none
|
||||
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
- [ ] I have also tested the issue on latest master, commit hash:
|
||||
138
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
138
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
name: Bug report
|
||||
description: Report incorrect or unexpected behavior of discord.js
|
||||
labels: [bug, need repro]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
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
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Issue description
|
||||
description: |
|
||||
Describe the issue in as much detail as possible.
|
||||
|
||||
Tip: You can attach images or log files by clicking this area to highlight it and then dragging files into it.
|
||||
placeholder: |
|
||||
Steps to reproduce with below code sample:
|
||||
1. do thing
|
||||
2. do thing in Discord client
|
||||
3. observe behavior
|
||||
4. see error logs below
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: codesample
|
||||
attributes:
|
||||
label: Code sample
|
||||
description: Include a reproducible, minimal code sample. This will be automatically formatted into code, so no need for backticks.
|
||||
render: typescript
|
||||
placeholder: |
|
||||
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('interactionCreate', async interaction => {
|
||||
if (!interaction.isCommand()) return;
|
||||
|
||||
if (interaction.commandName === 'ping') {
|
||||
await interaction.reply('Pong!');
|
||||
}
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
- type: input
|
||||
id: djs-version
|
||||
attributes:
|
||||
label: discord.js version
|
||||
description: Which version of discord.js are you using? Run `npm list discord.js` in your project directory and paste the output.
|
||||
placeholder: 13.x.x (we no longer support version 12 or earlier)
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: node-version
|
||||
attributes:
|
||||
label: Node.js version
|
||||
description: |
|
||||
Which version of Node.js are you using? Run `node --version` in your project directory and paste the output.
|
||||
If you are using TypeScript, please include its version (`npm list typescript`) as well.
|
||||
placeholder: Node.js version 16.6+ is required for version 13.0.0+
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: os
|
||||
attributes:
|
||||
label: Operating system
|
||||
description: Which OS does your application run on?
|
||||
- type: dropdown
|
||||
id: priority
|
||||
attributes:
|
||||
label: Priority this issue should have
|
||||
description: Please be realistic. If you need to elaborate on your reasoning, please use the Issue description field above.
|
||||
options:
|
||||
- Low (slightly annoying)
|
||||
- Medium (should be fixed soon)
|
||||
- High (immediate attention needed)
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: partials
|
||||
attributes:
|
||||
label: Which partials do you have configured?
|
||||
description: |
|
||||
Check your Client constructor for the `partials` key.
|
||||
|
||||
Tip: you can select multiple items
|
||||
options:
|
||||
- No Partials
|
||||
- USER
|
||||
- CHANNEL
|
||||
- GUILD_MEMBER
|
||||
- MESSAGE
|
||||
- REACTION
|
||||
- GUILD_SCHEDULED_EVENT
|
||||
multiple: true
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: intents
|
||||
attributes:
|
||||
label: Which gateway intents are you subscribing to?
|
||||
description: |
|
||||
Check your Client constructor for the `intents` key.
|
||||
|
||||
Tip: you can select multiple items
|
||||
options:
|
||||
- GUILDS
|
||||
- GUILD_MEMBERS
|
||||
- GUILD_BANS
|
||||
- GUILD_EMOJIS_AND_STICKERS
|
||||
- GUILD_INTEGRATIONS
|
||||
- GUILD_WEBHOOKS
|
||||
- GUILD_INVITES
|
||||
- GUILD_VOICE_STATES
|
||||
- GUILD_PRESENCES
|
||||
- GUILD_MESSAGES
|
||||
- GUILD_MESSAGE_REACTIONS
|
||||
- GUILD_MESSAGE_TYPING
|
||||
- DIRECT_MESSAGES
|
||||
- DIRECT_MESSAGE_REACTIONS
|
||||
- DIRECT_MESSAGE_TYPING
|
||||
- GUILD_SCHEDULED_EVENTS
|
||||
multiple: true
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: dev-release
|
||||
attributes:
|
||||
label: I have tested this issue on a development release
|
||||
placeholder: d23280c
|
||||
description: |
|
||||
The issue might already be fixed in a development release. This is not required, but helps us greatly.
|
||||
To install the latest development release run `npm i discord.js@dev` in your project directory.
|
||||
Run `npm list discord.js` and use the last part of the printed information (`d23280c` for `discord.js@xx.x.x-dev.1530234593.d23280c`)
|
||||
4
.github/ISSUE_TEMPLATE/config.yml
vendored
4
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,5 +1,5 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: Discord server
|
||||
url: https://discord.gg/bRCvFy9
|
||||
about: Have questions or need support? Please go to the Discord server, as issues that are just support-related will be closed and redirected there.
|
||||
url: https://discord.gg/djs
|
||||
about: Please visit our Discord server for questions and support requests.
|
||||
|
||||
26
.github/ISSUE_TEMPLATE/feature_request.md
vendored
26
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,26 +0,0 @@
|
||||
---
|
||||
|
||||
name: Feature request
|
||||
about: Request a feature for the core discord.js library
|
||||
title: ''
|
||||
labels: 'type: enhancement'
|
||||
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.
|
||||
-->
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
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.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
35
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
35
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
name: Feature request
|
||||
description: Request a new feature (documented features of the official Discord developer API only!)
|
||||
labels: [feature request]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
We can only implement features that Discord publishes, documents and merges into the Discord API documentation.
|
||||
We do not implement unreleased features.
|
||||
Use Discord for questions: https://discord.gg/djs
|
||||
- type: textarea
|
||||
id: description
|
||||
attributes:
|
||||
label: Feature
|
||||
description: A clear and concise description of what the problem is, or what feature you want to be implemented.
|
||||
placeholder: I'm always frustrated when..., Discord has recently released..., A good addition would be...
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: solution
|
||||
attributes:
|
||||
label: Ideal solution or implementation
|
||||
description: A clear and concise description of what you want to happen.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: alternatives
|
||||
attributes:
|
||||
label: Alternative solutions or implementations
|
||||
description: A clear and concise description of any alternative solutions or features you have considered.
|
||||
- type: textarea
|
||||
id: additional-context
|
||||
attributes:
|
||||
label: Other context
|
||||
description: Any other context, screenshots, or file uploads that help us understand your feature request.
|
||||
18
.github/PULL_REQUEST_TEMPLATE.md
vendored
18
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -1,12 +1,12 @@
|
||||
**Please describe the changes this PR makes and why it should be merged:**
|
||||
|
||||
**Status**
|
||||
**Status and versioning classification:**
|
||||
|
||||
- [ ] 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:**
|
||||
|
||||
- [ ] 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'
|
||||
32
.github/tsc.json
vendored
32
.github/tsc.json
vendored
@@ -1,18 +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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
27
.github/workflows/auto-deprecate.yml
vendored
Normal file
27
.github/workflows/auto-deprecate.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
name: npm auto deprecate
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '0 1 * * *'
|
||||
jobs:
|
||||
auto-deprecate:
|
||||
name: npm auto deprecate
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install node.js v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Deprecate versions
|
||||
run: 'yarn npm-deprecate --name "*dev*" --package "discord.js"'
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
27
.github/workflows/codeql-analysis.yml
vendored
27
.github/workflows/codeql-analysis.yml
vendored
@@ -1,27 +0,0 @@
|
||||
name: "CodeQL"
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 */12 * * 4'
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: javascript
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
49
.github/workflows/deploy.yml
vendored
49
.github/workflows/deploy.yml
vendored
@@ -1,49 +0,0 @@
|
||||
name: Deployment
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
- '!webpack'
|
||||
- '!docs'
|
||||
tags:
|
||||
- '*'
|
||||
jobs:
|
||||
docs:
|
||||
name: Documentation
|
||||
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 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 ci
|
||||
|
||||
- name: Build and deploy webpack
|
||||
uses: discordjs/action-webpack@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
97
.github/workflows/documentation.yml
vendored
Normal file
97
.github/workflows/documentation.yml
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
name: Documentation
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'stable'
|
||||
- '!docs'
|
||||
tags:
|
||||
- '*'
|
||||
jobs:
|
||||
build:
|
||||
name: Build documentation
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
BRANCH_NAME: ${{ steps.env.outputs.BRANCH_NAME }}
|
||||
BRANCH_OR_TAG: ${{ steps.env.outputs.BRANCH_OR_TAG }}
|
||||
SHA: ${{ steps.env.outputs.SHA }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install node.js v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Turbo cache
|
||||
id: turbo-cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: .turbo
|
||||
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
turbo-${{ github.job }}-${{ github.ref_name }}-
|
||||
|
||||
- name: Install dependencies
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Build docs
|
||||
run: yarn docs --cache-dir=".turbo"
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: docs
|
||||
path: packages/*/docs/docs.json
|
||||
|
||||
- name: Set outputs for upload job
|
||||
id: env
|
||||
run: |
|
||||
echo "::set-output name=BRANCH_NAME::${GITHUB_REF_NAME}"
|
||||
echo "::set-output name=BRANCH_OR_TAG::${GITHUB_REF_TYPE}"
|
||||
echo "::set-output name=SHA::${GITHUB_SHA}"
|
||||
|
||||
upload:
|
||||
name: Upload Documentation
|
||||
needs: build
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
package: ['builders', 'collection', 'discord.js', 'voice']
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
BRANCH_NAME: ${{ needs.build.outputs.BRANCH_NAME }}
|
||||
BRANCH_OR_TAG: ${{ needs.build.outputs.BRANCH_OR_TAG }}
|
||||
SHA: ${{ needs.build.outputs.SHA }}
|
||||
steps:
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: docs
|
||||
path: docs
|
||||
|
||||
- name: Checkout docs repository
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: 'discordjs/docs'
|
||||
token: ${{ secrets.DJS_DOCS }}
|
||||
path: 'out'
|
||||
|
||||
- name: Move docs to correct directory
|
||||
env:
|
||||
PACKAGE: ${{ matrix.package }}
|
||||
run: |
|
||||
mkdir -p out/${PACKAGE}
|
||||
mv docs/${PACKAGE}/docs/docs.json out/${PACKAGE}/${BRANCH_NAME}.json
|
||||
|
||||
- name: Commit and push
|
||||
run: |
|
||||
cd out
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
git add .
|
||||
git commit -m "Docs build for ${BRANCH_OR_TAG} ${BRANCH_NAME}: ${SHA}" || true
|
||||
git push
|
||||
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 }}
|
||||
45
.github/workflows/publish-dev.yml
vendored
Normal file
45
.github/workflows/publish-dev.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
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.js v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16
|
||||
registry-url: https://registry.npmjs.org/
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Check previous released version
|
||||
id: pre-release
|
||||
run: |
|
||||
if [[ $(npm view discord.js@dev version | grep -e "$(jq --raw-output '.version' packages/discord.js/package.json).*.$(git rev-parse --short HEAD | cut -b1-3)") ]]; \
|
||||
then echo '::set-output name=release::false'; \
|
||||
else echo '::set-output name=release::true'; fi
|
||||
|
||||
- name: Install dependencies
|
||||
if: steps.pre-release.outputs.release == 'true'
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Deprecate old versions
|
||||
if: steps.pre-release.outputs.release == 'true'
|
||||
run: npm deprecate discord.js@"~$(jq --raw-output '.version' packages/discord.js/package.json)" "no longer supported" || true
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
|
||||
- name: Publish
|
||||
if: steps.pre-release.outputs.release == 'true'
|
||||
run: |
|
||||
npm version --git-tag-version=false $(jq --raw-output '.version' packages/discord.js/package.json).$(date +%s).$(git rev-parse --short HEAD)
|
||||
yarn publish --tag dev || true
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
79
.github/workflows/test-cron.yml
vendored
79
.github/workflows/test-cron.yml
vendored
@@ -1,79 +0,0 @@
|
||||
name: Testing Cron
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 */12 * * *'
|
||||
jobs:
|
||||
lint:
|
||||
name: ESLint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Run ESLint
|
||||
uses: icrawl/action-eslint@v1
|
||||
|
||||
typings:
|
||||
name: TSLint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v1
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
|
||||
- name: Install dependencies
|
||||
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 v12
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
|
||||
- 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
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Test documentation
|
||||
run: npm run docs:test
|
||||
84
.github/workflows/test.yml
vendored
84
.github/workflows/test.yml
vendored
@@ -1,77 +1,31 @@
|
||||
name: Testing
|
||||
name: Tests
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
name: ESLint
|
||||
name: Lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
- name: Install node.js v16
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 12
|
||||
node-version: 16
|
||||
cache: 'yarn'
|
||||
cache-dependency-path: yarn.lock
|
||||
|
||||
- name: Turbo cache
|
||||
id: turbo-cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: .turbo
|
||||
key: turbo-${{ github.job }}-${{ github.ref_name }}-${{ github.sha }}
|
||||
restore-keys: |
|
||||
turbo-${{ github.job }}-${{ github.ref_name }}-
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
run: yarn --immutable
|
||||
|
||||
- name: Run ESLint
|
||||
uses: icrawl/action-eslint@v1
|
||||
|
||||
typings:
|
||||
name: TSLint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
|
||||
- name: Install dependencies
|
||||
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 v12
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
|
||||
- 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@v2
|
||||
|
||||
- name: Install Node v12
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Test documentation
|
||||
run: npm run docs:test
|
||||
- name: Run eslint
|
||||
run: yarn lint --cache-dir=".turbo"
|
||||
|
||||
26
.gitignore
vendored
26
.gitignore
vendored
@@ -1,23 +1,25 @@
|
||||
# Packages
|
||||
node_modules/
|
||||
yarn.lock
|
||||
|
||||
# Log files
|
||||
logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Authentication
|
||||
test/auth.json
|
||||
test/auth.js
|
||||
docs/deploy/deploy_key
|
||||
docs/deploy/deploy_key.pub
|
||||
deploy/deploy_key
|
||||
deploy/deploy_key.pub
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Env
|
||||
.env
|
||||
|
||||
# Dist
|
||||
dist/
|
||||
|
||||
# Miscellaneous
|
||||
.tmp/
|
||||
.vscode/
|
||||
.idea/
|
||||
docs/docs.json
|
||||
typings/index.js
|
||||
webpack/
|
||||
.DS_Store
|
||||
.turbo
|
||||
tsconfig.tsbuildinfo
|
||||
|
||||
4
.husky/commit-msg
Executable file
4
.husky/commit-msg
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
yarn 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"
|
||||
|
||||
yarn lint-staged && yarn lint:fix
|
||||
3
.lintstagedrc.json
Normal file
3
.lintstagedrc.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"*.{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
|
||||
8
.prettierrc.json
Normal file
8
.prettierrc.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"quoteProps": "as-needed",
|
||||
"trailingComma": "all",
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
{
|
||||
"ecmaVersion": 7,
|
||||
"libs": [],
|
||||
"loadEagerly": ["./src/*.js"],
|
||||
"dontLoad": ["node_modules/**"],
|
||||
"plugins": {
|
||||
"es_modules": {},
|
||||
"node": {},
|
||||
"doc_comment": {
|
||||
"fullDocs": true,
|
||||
"strong": true
|
||||
},
|
||||
"webpack": {
|
||||
"configPath": "./webpack.config.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"eslint.workingDirectories": [{ "pattern": "./packages/*" }]
|
||||
}
|
||||
116
README.md
116
README.md
@@ -5,30 +5,13 @@
|
||||
</p>
|
||||
<br />
|
||||
<p>
|
||||
<a href="https://discord.gg/bRCvFy9"><img src="https://img.shields.io/discord/222078108977594368?color=7289da&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>
|
||||
<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="Tests status" /></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
|
||||
@@ -41,43 +24,76 @@ 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/discord/erlpack) for significantly faster WebSocket data (de)serialisation (`npm install discord/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`)
|
||||
- [@discordjs/voice](https://github.com/discordjs/voice) for interacting with the Discord Voice API (`npm install @discordjs/voice`)
|
||||
|
||||
## 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}!`);
|
||||
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!');
|
||||
}
|
||||
});
|
||||
|
||||
client.login('token');
|
||||
@@ -86,14 +102,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)
|
||||
- [npm](https://www.npmjs.com/package/discord.js)
|
||||
- [Related libraries](https://discord.com/developers/docs/topics/community-resources#libraries)
|
||||
|
||||
### Extensions
|
||||
|
||||
@@ -103,9 +119,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).
|
||||
|
||||
61
cliff.toml
Normal file
61
cliff.toml
Normal file
@@ -0,0 +1,61 @@
|
||||
[changelog]
|
||||
header = """
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.\n
|
||||
"""
|
||||
body = """
|
||||
{% if version %}\
|
||||
# [{{ version | trim_start_matches(pat="v") }}]\
|
||||
{% if previous %}\
|
||||
{% if previous.version %}\
|
||||
(https://github.com/discordjs/discord.js/compare/{{ previous.version }}...{{ version }})\
|
||||
{% else %}
|
||||
(https://github.com/discordjs/discord.js/tree/{{ version }})\
|
||||
{% endif %}\
|
||||
{% endif %} \
|
||||
- ({{ timestamp | date(format="%Y-%m-%d") }})
|
||||
{% else %}\
|
||||
# [unreleased]
|
||||
{% endif %}\
|
||||
{% for group, commits in commits | group_by(attribute="group") %}
|
||||
## {{ group | upper_first }}
|
||||
{% for commit in commits %}
|
||||
- {% if commit.breaking %}\
|
||||
[**breaking**] \
|
||||
{% endif %}\
|
||||
{% if commit.scope %}\
|
||||
**{{commit.scope}}:** \
|
||||
{% endif %}\
|
||||
{{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}](https://github.com/discordjs/discord.js/commit/{{ commit.id }}))\
|
||||
{% endfor %}
|
||||
{% endfor %}\n
|
||||
"""
|
||||
trim = true
|
||||
footer = ""
|
||||
|
||||
[git]
|
||||
conventional_commits = true
|
||||
filter_unconventional = true
|
||||
commit_parsers = [
|
||||
{ message = "^feat", group = "Features"},
|
||||
{ message = "^fix", group = "Bug Fixes"},
|
||||
{ message = "^docs", group = "Documentation"},
|
||||
{ message = "^perf", group = "Performance"},
|
||||
{ message = "^refactor", group = "Refactor"},
|
||||
{ message = "^typings", group = "Typings"},
|
||||
{ message = "^types", group = "Typings"},
|
||||
{ message = ".*deprecated", body = ".*deprecated", group = "Deprecation"},
|
||||
{ message = "^revert", skip = true},
|
||||
{ message = "^style", group = "Styling"},
|
||||
{ message = "^test", group = "Testing"},
|
||||
{ message = "^chore", skip = true},
|
||||
{ message = "^ci", skip = true},
|
||||
{ message = "^build", skip = true},
|
||||
{ body = ".*security", group = "Security"},
|
||||
]
|
||||
filter_commits = true
|
||||
tag_pattern = "[0-9]*"
|
||||
skip_tags = "v[0-9]*|11|12"
|
||||
ignore_tags = ""
|
||||
topo_order = false
|
||||
sort_commits = "newest"
|
||||
@@ -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://discord.com/developers/applications
|
||||
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://discord.com/developers/applications
|
||||
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://discord.com/developers/applications
|
||||
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://discord.com/developers/applications
|
||||
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://discord.com/developers/applications
|
||||
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://discord.com/developers/applications
|
||||
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://discord.com/developers/applications
|
||||
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://discord.com/developers/applications
|
||||
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://discord.com/developers/applications
|
||||
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://discord.com/developers/applications
|
||||
client.login('your token here');
|
||||
@@ -1,19 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Send a message using a webhook
|
||||
*/
|
||||
|
||||
// Import the discord.js module
|
||||
const Discord = require('discord.js');
|
||||
/*
|
||||
* Create a new webhook
|
||||
* The Webhooks ID and token can be found in the URL, when you request that URL, or in the response body.
|
||||
* https://discord.com/api/webhooks/12345678910/T0kEn0fw3Bh00K
|
||||
* ^^^^^^^^^^ ^^^^^^^^^^^^
|
||||
* Webhook ID Webhook Token
|
||||
*/
|
||||
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://img.shields.io/discord/222078108977594368?color=7289da&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://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://discord.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/discord/erlpack) for significantly faster WebSocket data (de)serialisation (`npm install discord/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 +0,0 @@
|
||||
- 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
|
||||
@@ -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>
|
||||
```
|
||||
@@ -1,95 +0,0 @@
|
||||
import Discord from '../src/index.js';
|
||||
|
||||
export default Discord;
|
||||
|
||||
export const {
|
||||
BaseClient,
|
||||
Client,
|
||||
Shard,
|
||||
ShardClientUtil,
|
||||
ShardingManager,
|
||||
WebhookClient,
|
||||
ActivityFlags,
|
||||
BitField,
|
||||
Collection,
|
||||
Constants,
|
||||
DataResolver,
|
||||
BaseManager,
|
||||
DiscordAPIError,
|
||||
HTTPError,
|
||||
MessageFlags,
|
||||
Intents,
|
||||
Permissions,
|
||||
Speaking,
|
||||
Snowflake,
|
||||
SnowflakeUtil,
|
||||
Structures,
|
||||
SystemChannelFlags,
|
||||
UserFlags,
|
||||
Util,
|
||||
version,
|
||||
ChannelManager,
|
||||
GuildChannelManager,
|
||||
GuildEmojiManager,
|
||||
GuildEmojiRoleManager,
|
||||
GuildMemberManager,
|
||||
GuildMemberRoleManager,
|
||||
GuildManager,
|
||||
ReactionManager,
|
||||
ReactionUserManager,
|
||||
MessageManager,
|
||||
PresenceManager,
|
||||
RoleManager,
|
||||
UserManager,
|
||||
discordSort,
|
||||
escapeMarkdown,
|
||||
fetchRecommendedShards,
|
||||
resolveColor,
|
||||
resolveString,
|
||||
splitMessage,
|
||||
Application,
|
||||
Base,
|
||||
Activity,
|
||||
APIMessage,
|
||||
BaseGuildEmoji,
|
||||
CategoryChannel,
|
||||
Channel,
|
||||
ClientApplication,
|
||||
ClientUser,
|
||||
Collector,
|
||||
DMChannel,
|
||||
Emoji,
|
||||
Guild,
|
||||
GuildAuditLogs,
|
||||
GuildChannel,
|
||||
GuildEmoji,
|
||||
GuildMember,
|
||||
GuildPreview,
|
||||
GuildTemplate,
|
||||
Integration,
|
||||
Invite,
|
||||
Message,
|
||||
MessageAttachment,
|
||||
MessageCollector,
|
||||
MessageEmbed,
|
||||
MessageMentions,
|
||||
MessageReaction,
|
||||
NewsChannel,
|
||||
PermissionOverwrites,
|
||||
Presence,
|
||||
ClientPresence,
|
||||
ReactionCollector,
|
||||
ReactionEmoji,
|
||||
RichPresenceAssets,
|
||||
Role,
|
||||
StoreChannel,
|
||||
Team,
|
||||
TeamMember,
|
||||
TextChannel,
|
||||
User,
|
||||
VoiceChannel,
|
||||
VoiceRegion,
|
||||
VoiceState,
|
||||
Webhook,
|
||||
WebSocket
|
||||
} = Discord;
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"plugins": ["node_modules/jsdoc-strip-async-await"]
|
||||
}
|
||||
11518
package-lock.json
generated
11518
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
264
package.json
264
package.json
@@ -1,163 +1,105 @@
|
||||
{
|
||||
"name": "discord.js",
|
||||
"version": "12.5.0",
|
||||
"description": "A powerful library for interacting with the Discord API",
|
||||
"main": "./src/index",
|
||||
"types": "./typings/index.d.ts",
|
||||
"exports": {
|
||||
".": [
|
||||
{
|
||||
"require": "./src/index.js",
|
||||
"import": "./esm/discord.mjs"
|
||||
},
|
||||
"./src/index.js"
|
||||
],
|
||||
"./esm": "./esm/discord.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 src/**/*.js typings/**/*.ts",
|
||||
"build:browser": "webpack",
|
||||
"prepublishOnly": "npm run test && cross-env NODE_ENV=production npm run build:browser"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/discordjs/discord.js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"discord",
|
||||
"api",
|
||||
"bot",
|
||||
"client",
|
||||
"node",
|
||||
"discordapp"
|
||||
],
|
||||
"author": "Amish Shah <amishshah.2k@gmail.com>",
|
||||
"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.6",
|
||||
"@discordjs/form-data": "^3.0.1",
|
||||
"abort-controller": "^3.0.0",
|
||||
"node-fetch": "^2.6.1",
|
||||
"prism-media": "^1.2.2",
|
||||
"setimmediate": "^1.0.5",
|
||||
"tweetnacl": "^1.0.3",
|
||||
"ws": "^7.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^11.0.0",
|
||||
"@commitlint/config-angular": "^11.0.0",
|
||||
"@types/node": "^12.12.6",
|
||||
"@types/ws": "^7.2.7",
|
||||
"cross-env": "^7.0.2",
|
||||
"discord.js-docgen": "git+https://github.com/discordjs/docgen.git",
|
||||
"dtslint": "^4.0.4",
|
||||
"eslint": "^7.11.0",
|
||||
"eslint-config-prettier": "^6.13.0",
|
||||
"eslint-plugin-import": "^2.22.1",
|
||||
"eslint-plugin-prettier": "^3.1.4",
|
||||
"husky": "^4.3.0",
|
||||
"jest": "^26.6.0",
|
||||
"json-filter-loader": "^1.0.0",
|
||||
"lint-staged": "^10.4.2",
|
||||
"prettier": "^2.1.2",
|
||||
"terser-webpack-plugin": "^4.2.3",
|
||||
"tslint": "^6.1.3",
|
||||
"typescript": "^4.0.3",
|
||||
"webpack": "^4.44.2",
|
||||
"webpack-cli": "^3.3.12"
|
||||
},
|
||||
"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"
|
||||
},
|
||||
"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"
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
"prettier": {
|
||||
"singleQuote": true,
|
||||
"printWidth": 120,
|
||||
"trailingComma": "all",
|
||||
"endOfLine": "lf",
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
"name": "@discordjs/discord.js",
|
||||
"version": "0.0.0",
|
||||
"description": "A powerful library for interacting with the Discord API",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "turbo run build",
|
||||
"test": "turbo run test",
|
||||
"lint": "turbo run lint",
|
||||
"lint:fix": "turbo run lint:fix",
|
||||
"format": "turbo run format",
|
||||
"fmt": "turbo run format",
|
||||
"postinstall": "is-ci || husky install",
|
||||
"docs": "turbo run docs",
|
||||
"changelog": "turbo run changelog",
|
||||
"update": "yarn upgrade-interactive --latest"
|
||||
},
|
||||
"contributors": [
|
||||
"Crawl <icrawltogo@gmail.com>",
|
||||
"Amish Shah <amishshah.2k@gmail.com>",
|
||||
"Vlad Frangu <kingdgrizzle@gmail.com>",
|
||||
"SpaceEEC <spaceeec@yahoo.com>",
|
||||
"Antonio Roman <kyradiscord@gmail.com>"
|
||||
],
|
||||
"keywords": [
|
||||
"discord",
|
||||
"api",
|
||||
"bot",
|
||||
"client",
|
||||
"node",
|
||||
"discordapp"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/discordjs/discord.js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^16.0.1",
|
||||
"@commitlint/config-angular": "^16.0.0",
|
||||
"@favware/npm-deprecate": "^1.0.4",
|
||||
"conventional-changelog-cli": "^2.2.2",
|
||||
"husky": "^7.0.4",
|
||||
"lint-staged": "^12.1.4",
|
||||
"prettier": "^2.5.1",
|
||||
"turbo": "^1.0.24-canary.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.6.0"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"turbo": {
|
||||
"baseBranch": "origin/main",
|
||||
"pipeline": {
|
||||
"build": {
|
||||
"dependsOn": [
|
||||
"^build"
|
||||
],
|
||||
"outputs": [
|
||||
"dist/**",
|
||||
"docs/docs.json"
|
||||
]
|
||||
},
|
||||
"test": {
|
||||
"dependsOn": [
|
||||
"^build"
|
||||
],
|
||||
"outputs": []
|
||||
},
|
||||
"lint": {
|
||||
"dependsOn": [
|
||||
"^build"
|
||||
],
|
||||
"outputs": []
|
||||
},
|
||||
"lint:fix": {
|
||||
"dependsOn": [
|
||||
"^build"
|
||||
],
|
||||
"outputs": []
|
||||
},
|
||||
"format": {
|
||||
"outputs": []
|
||||
},
|
||||
"docs": {
|
||||
"outputs": [
|
||||
"docs/docs.json"
|
||||
]
|
||||
},
|
||||
"changelog": {
|
||||
"dependsOn": [
|
||||
"^build"
|
||||
],
|
||||
"outputs": [
|
||||
"CHANGELOG.md"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
packages/builders/.eslintrc.json
Normal file
16
packages/builders/.eslintrc.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"root": true,
|
||||
"extends": "marine/prettier/node",
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.eslint.json",
|
||||
"extraFileExtensions": [".mjs"]
|
||||
},
|
||||
"ignorePatterns": ["**/dist/*"],
|
||||
"env": {
|
||||
"jest": true
|
||||
},
|
||||
"rules": {
|
||||
"no-redeclare": 0,
|
||||
"@typescript-eslint/naming-convention": 0
|
||||
}
|
||||
}
|
||||
26
packages/builders/.gitignore
vendored
Normal file
26
packages/builders/.gitignore
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
# Packages
|
||||
node_modules/
|
||||
|
||||
# Log files
|
||||
logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Env
|
||||
.env
|
||||
|
||||
# Dist
|
||||
dist/
|
||||
typings/
|
||||
docs/**/*
|
||||
!docs/index.yml
|
||||
!docs/README.md
|
||||
|
||||
# Miscellaneous
|
||||
.tmp/
|
||||
coverage/
|
||||
8
packages/builders/.prettierrc.json
Normal file
8
packages/builders/.prettierrc.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"quoteProps": "as-needed",
|
||||
"trailingComma": "all",
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
3
packages/builders/.versionrc
Normal file
3
packages/builders/.versionrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"releaseCommitMessageFormat": "chore(Release): publish"
|
||||
}
|
||||
153
packages/builders/CHANGELOG.md
Normal file
153
packages/builders/CHANGELOG.md
Normal file
@@ -0,0 +1,153 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
|
||||
# [0.11.0](https://github.com/discordjs/builders/compare/v0.10.0...v0.11.0) (2021-12-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **ApplicationCommandOptions:** clean up code for builder options ([#68](https://github.com/discordjs/builders/issues/68)) ([b5d0b15](https://github.com/discordjs/builders/commit/b5d0b157b1262bd01fa011f8e0cf33adb82776e7))
|
||||
|
||||
|
||||
|
||||
# [0.10.0](https://github.com/discordjs/builders/compare/v0.9.0...v0.10.0) (2021-12-24)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* use zod instead of ow for max/min option validation ([#66](https://github.com/discordjs/builders/issues/66)) ([beb35fb](https://github.com/discordjs/builders/commit/beb35fb1f65bd6be2321e17cc792f67e8615fd48))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add max/min option for int and number builder options ([#47](https://github.com/discordjs/builders/issues/47)) ([2e1e860](https://github.com/discordjs/builders/commit/2e1e860b46e3453398b20df63dabb6d4325e32d1))
|
||||
|
||||
|
||||
|
||||
# [0.9.0](https://github.com/discordjs/builders/compare/v0.8.2...v0.9.0) (2021-12-02)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* replace ow with zod ([#58](https://github.com/discordjs/builders/issues/58)) ([0b6fb81](https://github.com/discordjs/builders/commit/0b6fb8161b858e42781855fb73aaa873fec58160))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **SlashCommandBuilder:** add autocomplete ([#53](https://github.com/discordjs/builders/issues/53)) ([05b07a7](https://github.com/discordjs/builders/commit/05b07a7e88848188c27d7380d9f948cba25ef778))
|
||||
|
||||
|
||||
|
||||
## [0.8.2](https://github.com/discordjs/builders/compare/v0.8.1...v0.8.2) (2021-10-30)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* downgrade ow because of esm issues ([#55](https://github.com/discordjs/builders/issues/55)) ([3722d2c](https://github.com/discordjs/builders/commit/3722d2c1109a7a5c0abad63c1a7eb944df6e46c8))
|
||||
|
||||
|
||||
|
||||
## [0.8.1](https://github.com/discordjs/builders/compare/v0.8.0...v0.8.1) (2021-10-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* documentation ([e33ec8d](https://github.com/discordjs/builders/commit/e33ec8dfd5785312f82e0afb017a3dac614fd71d))
|
||||
|
||||
|
||||
|
||||
# [0.8.0](https://github.com/discordjs/builders/compare/v0.7.0...v0.8.0) (2021-10-29)
|
||||
|
||||
|
||||
|
||||
# [0.7.0](https://github.com/discordjs/builders/compare/v0.6.0...v0.7.0) (2021-10-18)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* properly type `toJSON` methods ([#34](https://github.com/discordjs/builders/issues/34)) ([7723ad0](https://github.com/discordjs/builders/commit/7723ad0da169386e638188de220451a97513bc25))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **ContextMenus:** add context menu command builder ([#29](https://github.com/discordjs/builders/issues/29)) ([f0641e5](https://github.com/discordjs/builders/commit/f0641e55733de8992600f3082bcf054e6f815cf7))
|
||||
* add support for channel types on channel options ([#41](https://github.com/discordjs/builders/issues/41)) ([f6c187e](https://github.com/discordjs/builders/commit/f6c187e0ad6ebe03e65186ece3e95cb1db5aeb50))
|
||||
|
||||
|
||||
|
||||
# [0.6.0](https://github.com/discordjs/builders/compare/v0.5.0...v0.6.0) (2021-08-24)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **SlashCommandBuilder:** allow subcommands and groups to coexist at the root level ([#26](https://github.com/discordjs/builders/issues/26)) ([0be4daf](https://github.com/discordjs/builders/commit/0be4dafdfc0b5747c880be0078c00ada913eb4fb))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* create `Embed` builder ([#11](https://github.com/discordjs/builders/issues/11)) ([eb942a4](https://github.com/discordjs/builders/commit/eb942a4d1f3bcec9a4e370b6af602a713ad8f9b7))
|
||||
* **SlashCommandBuilder:** create setDefaultPermission function ([#19](https://github.com/discordjs/builders/issues/19)) ([5d53759](https://github.com/discordjs/builders/commit/5d537593937a8da330153ce4711b7d093a80330e))
|
||||
* **SlashCommands:** add number option type ([#23](https://github.com/discordjs/builders/issues/23)) ([1563991](https://github.com/discordjs/builders/commit/1563991d421bb07bf7a412c87e7613692d770f04))
|
||||
|
||||
|
||||
|
||||
# [0.5.0](https://github.com/discordjs/builders/compare/v0.3.0...v0.5.0) (2021-08-10)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **Formatters:** add `formatEmoji` ([#20](https://github.com/discordjs/builders/issues/20)) ([c3d8bb5](https://github.com/discordjs/builders/commit/c3d8bb5363a1d46b45c0def4277da6921e2ba209))
|
||||
|
||||
|
||||
|
||||
# [0.4.0](https://github.com/discordjs/builders/compare/v0.3.0...v0.4.0) (2021-08-05)
|
||||
|
||||
### Features
|
||||
|
||||
* `sub command` => `subcommand` ([#18](https://github.com/discordjs/builders/pull/18)) ([95599c5](https://github.com/discordjs/builders/commit/95599c5b5366ebd054c4c277c52f1a44cda1209d))
|
||||
|
||||
|
||||
|
||||
# [0.3.0](https://github.com/discordjs/builders/compare/v0.2.0...v0.3.0) (2021-08-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **Shrug:** Update comment ([#14](https://github.com/discordjs/builders/issues/14)) ([6fa6c40](https://github.com/discordjs/builders/commit/6fa6c405f2ea733811677d3d1bfb1e2806d504d5))
|
||||
* shrug face rendering ([#13](https://github.com/discordjs/builders/issues/13)) ([6ad24ec](https://github.com/discordjs/builders/commit/6ad24ecd96c82b0f576e78e9e53fc7bf9c36ef5d))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **formatters:** mentions ([#9](https://github.com/discordjs/builders/issues/9)) ([f83fe99](https://github.com/discordjs/builders/commit/f83fe99b83188ed999845751ffb005c687dbd60a))
|
||||
* **Formatters:** Add a spoiler function ([#16](https://github.com/discordjs/builders/issues/16)) ([c213a6a](https://github.com/discordjs/builders/commit/c213a6abb114f65653017a4edec4bdba2162d771))
|
||||
* **SlashCommands:** add slash command builders ([#3](https://github.com/discordjs/builders/issues/3)) ([6aa3af0](https://github.com/discordjs/builders/commit/6aa3af07b0ee342fff91f080914bb12b3ab773f8))
|
||||
* shrug, tableflip and unflip strings ([#5](https://github.com/discordjs/builders/issues/5)) ([de5fa82](https://github.com/discordjs/builders/commit/de5fa823cd6f1feba5b2d0a63b2cb1761dfd1814))
|
||||
|
||||
|
||||
|
||||
# [0.2.0](https://github.com/discordjs/builders/compare/v0.1.1...v0.2.0) (2021-07-03)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **Formatters:** added `hyperlink` and `hideLinkEmbed` ([#4](https://github.com/discordjs/builders/issues/4)) ([c532daf](https://github.com/discordjs/builders/commit/c532daf2ba2feae75bf9668f63462e96a5314cff))
|
||||
|
||||
|
||||
|
||||
## [0.1.1](https://github.com/discordjs/builders/compare/v0.1.0...v0.1.1) (2021-06-30)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **Deps:** added `tslib` as dependency ([#2](https://github.com/discordjs/builders/issues/2)) ([5576ff3](https://github.com/discordjs/builders/commit/5576ff3b67136b957bed0ab8a4c655d5de322813))
|
||||
|
||||
|
||||
|
||||
# 0.1.0 (2021-06-30)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* added message formatters ([#1](https://github.com/discordjs/builders/issues/1)) ([765e46d](https://github.com/discordjs/builders/commit/765e46dac96c4e49d350243e5fad34c2bc738a7c))
|
||||
191
packages/builders/LICENSE
Normal file
191
packages/builders/LICENSE
Normal file
@@ -0,0 +1,191 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
Copyright 2021 Noel Buechler
|
||||
Copyright 2021 Vlad Frangu
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
53
packages/builders/README.md
Normal file
53
packages/builders/README.md
Normal file
@@ -0,0 +1,53 @@
|
||||
<div align="center">
|
||||
<br />
|
||||
<p>
|
||||
<a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a>
|
||||
</p>
|
||||
<br />
|
||||
<p>
|
||||
<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/@discordjs/builders"><img src="https://img.shields.io/npm/v/@discordjs/builders.svg?maxAge=3600" alt="npm version" /></a>
|
||||
<a href="https://www.npmjs.com/package/@discordjs/builders"><img src="https://img.shields.io/npm/dt/@discordjs/builders.svg?maxAge=3600" alt="npm downloads" /></a>
|
||||
<a href="https://github.com/discordjs/builders/actions"><img src="https://github.com/discordjs/builders/workflows/Tests/badge.svg" alt="Build status" /></a>
|
||||
<a href="https://codecov.io/gh/discordjs/builders"><img src="https://codecov.io/gh/discordjs/builders/branch/main/graph/badge.svg" alt="Code coverage" /></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
## Installation
|
||||
|
||||
**Node.js 16.6.0 or newer is required.**
|
||||
|
||||
```sh-session
|
||||
npm install @discordjs/builders
|
||||
yarn add @discordjs/builders
|
||||
pnpm add @discordjs/builders
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
Here are some examples for the builders and utilities you can find in this package:
|
||||
|
||||
- [Slash Command Builders](./docs/examples/Slash%20Command%20Builders.md)
|
||||
|
||||
## Links
|
||||
|
||||
- [Website](https://discord.js.org/) ([source](https://github.com/discordjs/website))
|
||||
- [Documentation](https://discord.js.org/#/docs/builders)
|
||||
- [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/builders)
|
||||
- [npm](https://www.npmjs.com/package/@discordjs/builders)
|
||||
- [Related libraries](https://discord.com/developers/docs/topics/community-resources#libraries)
|
||||
|
||||
## 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/builders).
|
||||
See [the contribution guide](https://github.com/discordjs/builders/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/djs).
|
||||
@@ -0,0 +1,89 @@
|
||||
import { ContextMenuCommandAssertions, ContextMenuCommandBuilder } from '../../src/index';
|
||||
|
||||
const getBuilder = () => new ContextMenuCommandBuilder();
|
||||
|
||||
describe('Context Menu Commands', () => {
|
||||
describe('Assertions tests', () => {
|
||||
test('GIVEN valid name THEN does not throw error', () => {
|
||||
expect(() => ContextMenuCommandAssertions.validateName('ping')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid name THEN throw error', () => {
|
||||
expect(() => ContextMenuCommandAssertions.validateName(null)).toThrowError();
|
||||
|
||||
// Too short of a name
|
||||
expect(() => ContextMenuCommandAssertions.validateName('')).toThrowError();
|
||||
|
||||
// Invalid characters used
|
||||
expect(() => ContextMenuCommandAssertions.validateName('ABC123$%^&')).toThrowError();
|
||||
|
||||
// Too long of a name
|
||||
expect(() =>
|
||||
ContextMenuCommandAssertions.validateName('qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm'),
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid type THEN does not throw error', () => {
|
||||
expect(() => ContextMenuCommandAssertions.validateType(3)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid type THEN throw error', () => {
|
||||
expect(() => ContextMenuCommandAssertions.validateType(null)).toThrowError();
|
||||
|
||||
// Out of range
|
||||
expect(() => ContextMenuCommandAssertions.validateType(1)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid required parameters THEN does not throw error', () => {
|
||||
expect(() => ContextMenuCommandAssertions.validateRequiredParameters('owo', 2)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid default_permission THEN does not throw error', () => {
|
||||
expect(() => ContextMenuCommandAssertions.validateDefaultPermission(true)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid default_permission THEN throw error', () => {
|
||||
expect(() => ContextMenuCommandAssertions.validateDefaultPermission(null)).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ContextMenuCommandBuilder', () => {
|
||||
describe('Builder tests', () => {
|
||||
test('GIVEN empty builder THEN throw error when calling toJSON', () => {
|
||||
expect(() => getBuilder().toJSON()).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid builder THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setName('example').setType(3).toJSON()).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid name THEN throw error', () => {
|
||||
expect(() => getBuilder().setName('$$$')).toThrowError();
|
||||
|
||||
expect(() => getBuilder().setName(' ')).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid names THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setName('hi_there')).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().setName('A COMMAND')).not.toThrowError();
|
||||
|
||||
// Translation: a_command
|
||||
expect(() => getBuilder().setName('o_comandă')).not.toThrowError();
|
||||
|
||||
// Translation: thx (according to GTranslate)
|
||||
expect(() => getBuilder().setName('どうも')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid types THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setType(2)).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().setType(3)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid builder with defaultPermission false THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setName('foo').setDefaultPermission(false)).not.toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,201 @@
|
||||
import {
|
||||
APIApplicationCommandBooleanOption,
|
||||
APIApplicationCommandChannelOption,
|
||||
APIApplicationCommandIntegerOption,
|
||||
APIApplicationCommandMentionableOption,
|
||||
APIApplicationCommandNumberOption,
|
||||
APIApplicationCommandRoleOption,
|
||||
APIApplicationCommandStringOption,
|
||||
APIApplicationCommandUserOption,
|
||||
ApplicationCommandOptionType,
|
||||
ChannelType,
|
||||
} from 'discord-api-types/v9';
|
||||
import {
|
||||
SlashCommandBooleanOption,
|
||||
SlashCommandChannelOption,
|
||||
SlashCommandIntegerOption,
|
||||
SlashCommandMentionableOption,
|
||||
SlashCommandNumberOption,
|
||||
SlashCommandRoleOption,
|
||||
SlashCommandStringOption,
|
||||
SlashCommandUserOption,
|
||||
} from '../../../src/index';
|
||||
|
||||
const getBooleanOption = () =>
|
||||
new SlashCommandBooleanOption().setName('owo').setDescription('Testing 123').setRequired(true);
|
||||
|
||||
const getChannelOption = () =>
|
||||
new SlashCommandChannelOption()
|
||||
.setName('owo')
|
||||
.setDescription('Testing 123')
|
||||
.setRequired(true)
|
||||
.addChannelType(ChannelType.GuildText);
|
||||
|
||||
const getStringOption = () =>
|
||||
new SlashCommandStringOption().setName('owo').setDescription('Testing 123').setRequired(true);
|
||||
|
||||
const getIntegerOption = () =>
|
||||
new SlashCommandIntegerOption()
|
||||
.setName('owo')
|
||||
.setDescription('Testing 123')
|
||||
.setRequired(true)
|
||||
.setMinValue(1)
|
||||
.setMaxValue(10);
|
||||
|
||||
const getNumberOption = () =>
|
||||
new SlashCommandNumberOption()
|
||||
.setName('owo')
|
||||
.setDescription('Testing 123')
|
||||
.setRequired(true)
|
||||
.setMinValue(1)
|
||||
.setMaxValue(10);
|
||||
|
||||
const getUserOption = () => new SlashCommandUserOption().setName('owo').setDescription('Testing 123').setRequired(true);
|
||||
|
||||
const getRoleOption = () => new SlashCommandRoleOption().setName('owo').setDescription('Testing 123').setRequired(true);
|
||||
|
||||
const getMentionableOption = () =>
|
||||
new SlashCommandMentionableOption().setName('owo').setDescription('Testing 123').setRequired(true);
|
||||
|
||||
describe('Application Command toJSON() results', () => {
|
||||
test('GIVEN a boolean option THEN calling toJSON should return a valid JSON', () => {
|
||||
expect(getBooleanOption().toJSON()).toEqual<APIApplicationCommandBooleanOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Boolean,
|
||||
required: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN a channel option THEN calling toJSON should return a valid JSON', () => {
|
||||
expect(getChannelOption().toJSON()).toEqual<APIApplicationCommandChannelOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Channel,
|
||||
required: true,
|
||||
channel_types: [ChannelType.GuildText],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN a integer option THEN calling toJSON should return a valid JSON', () => {
|
||||
expect(getIntegerOption().toJSON()).toEqual<APIApplicationCommandIntegerOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Integer,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
});
|
||||
|
||||
expect(
|
||||
getIntegerOption().setAutocomplete(true).setChoices([]).toJSON(),
|
||||
).toEqual<APIApplicationCommandIntegerOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Integer,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
autocomplete: true,
|
||||
// @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types
|
||||
choices: [],
|
||||
});
|
||||
|
||||
expect(getIntegerOption().addChoice('uwu', 1).toJSON()).toEqual<APIApplicationCommandIntegerOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Integer,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
choices: [{ name: 'uwu', value: 1 }],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN a mentionable option THEN calling toJSON should return a valid JSON', () => {
|
||||
expect(getMentionableOption().toJSON()).toEqual<APIApplicationCommandMentionableOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Mentionable,
|
||||
required: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN a number option THEN calling toJSON should return a valid JSON', () => {
|
||||
expect(getNumberOption().toJSON()).toEqual<APIApplicationCommandNumberOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Number,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
});
|
||||
|
||||
expect(getNumberOption().setAutocomplete(true).setChoices([]).toJSON()).toEqual<APIApplicationCommandNumberOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Number,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
autocomplete: true,
|
||||
// @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types
|
||||
choices: [],
|
||||
});
|
||||
|
||||
expect(getNumberOption().addChoice('uwu', 1).toJSON()).toEqual<APIApplicationCommandNumberOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Number,
|
||||
required: true,
|
||||
max_value: 10,
|
||||
min_value: 1,
|
||||
choices: [{ name: 'uwu', value: 1 }],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN a role option THEN calling toJSON should return a valid JSON', () => {
|
||||
expect(getRoleOption().toJSON()).toEqual<APIApplicationCommandRoleOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.Role,
|
||||
required: true,
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN a string option THEN calling toJSON should return a valid JSON', () => {
|
||||
expect(getStringOption().toJSON()).toEqual<APIApplicationCommandStringOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
});
|
||||
|
||||
expect(getStringOption().setAutocomplete(true).setChoices([]).toJSON()).toEqual<APIApplicationCommandStringOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
autocomplete: true,
|
||||
// @ts-expect-error TODO: you *can* send an empty array with autocomplete: true, should correct that in types
|
||||
choices: [],
|
||||
});
|
||||
|
||||
expect(getStringOption().addChoice('uwu', '1').toJSON()).toEqual<APIApplicationCommandStringOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.String,
|
||||
required: true,
|
||||
choices: [{ name: 'uwu', value: '1' }],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN a user option THEN calling toJSON should return a valid JSON', () => {
|
||||
expect(getUserOption().toJSON()).toEqual<APIApplicationCommandUserOption>({
|
||||
name: 'owo',
|
||||
description: 'Testing 123',
|
||||
type: ApplicationCommandOptionType.User,
|
||||
required: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,427 @@
|
||||
import { APIApplicationCommandOptionChoice, ChannelType } from 'discord-api-types/v9';
|
||||
import {
|
||||
SlashCommandAssertions,
|
||||
SlashCommandBooleanOption,
|
||||
SlashCommandBuilder,
|
||||
SlashCommandChannelOption,
|
||||
SlashCommandIntegerOption,
|
||||
SlashCommandMentionableOption,
|
||||
SlashCommandNumberOption,
|
||||
SlashCommandRoleOption,
|
||||
SlashCommandStringOption,
|
||||
SlashCommandSubcommandBuilder,
|
||||
SlashCommandSubcommandGroupBuilder,
|
||||
SlashCommandUserOption,
|
||||
} from '../../../src/index';
|
||||
|
||||
const largeArray = Array.from({ length: 26 }, () => 1 as unknown as APIApplicationCommandOptionChoice);
|
||||
|
||||
const getBuilder = () => new SlashCommandBuilder();
|
||||
const getNamedBuilder = () => getBuilder().setName('example').setDescription('Example command');
|
||||
const getStringOption = () => new SlashCommandStringOption().setName('owo').setDescription('Testing 123');
|
||||
const getIntegerOption = () => new SlashCommandIntegerOption().setName('owo').setDescription('Testing 123');
|
||||
const getNumberOption = () => new SlashCommandNumberOption().setName('owo').setDescription('Testing 123');
|
||||
const getBooleanOption = () => new SlashCommandBooleanOption().setName('owo').setDescription('Testing 123');
|
||||
const getUserOption = () => new SlashCommandUserOption().setName('owo').setDescription('Testing 123');
|
||||
const getChannelOption = () => new SlashCommandChannelOption().setName('owo').setDescription('Testing 123');
|
||||
const getRoleOption = () => new SlashCommandRoleOption().setName('owo').setDescription('Testing 123');
|
||||
const getMentionableOption = () => new SlashCommandMentionableOption().setName('owo').setDescription('Testing 123');
|
||||
const getSubcommandGroup = () => new SlashCommandSubcommandGroupBuilder().setName('owo').setDescription('Testing 123');
|
||||
const getSubcommand = () => new SlashCommandSubcommandBuilder().setName('owo').setDescription('Testing 123');
|
||||
|
||||
class Collection {
|
||||
public get [Symbol.toStringTag]() {
|
||||
return 'Map';
|
||||
}
|
||||
}
|
||||
|
||||
describe('Slash Commands', () => {
|
||||
describe('Assertions tests', () => {
|
||||
test('GIVEN valid name THEN does not throw error', () => {
|
||||
expect(() => SlashCommandAssertions.validateName('ping')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid name THEN throw error', () => {
|
||||
expect(() => SlashCommandAssertions.validateName(null)).toThrowError();
|
||||
|
||||
// Too short of a name
|
||||
expect(() => SlashCommandAssertions.validateName('')).toThrowError();
|
||||
|
||||
// Invalid characters used
|
||||
expect(() => SlashCommandAssertions.validateName('ABC123$%^&')).toThrowError();
|
||||
|
||||
// Too long of a name
|
||||
expect(() =>
|
||||
SlashCommandAssertions.validateName('qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm'),
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid description THEN does not throw error', () => {
|
||||
expect(() => SlashCommandAssertions.validateDescription('This is an OwO moment fur sure!~')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid description THEN throw error', () => {
|
||||
expect(() => SlashCommandAssertions.validateDescription(null)).toThrowError();
|
||||
|
||||
// Too short of a description
|
||||
expect(() => SlashCommandAssertions.validateDescription('')).toThrowError();
|
||||
|
||||
// Too long of a description
|
||||
expect(() =>
|
||||
SlashCommandAssertions.validateDescription(
|
||||
'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Magnam autem libero expedita vitae accusamus nostrum ipsam tempore repudiandae deserunt ipsum facilis, velit fugiat facere accusantium, explicabo corporis aliquam non quos.',
|
||||
),
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid default_permission THEN does not throw error', () => {
|
||||
expect(() => SlashCommandAssertions.validateDefaultPermission(true)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid default_permission THEN throw error', () => {
|
||||
expect(() => SlashCommandAssertions.validateDefaultPermission(null)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid array of options or choices THEN does not throw error', () => {
|
||||
expect(() => SlashCommandAssertions.validateMaxOptionsLength([])).not.toThrowError();
|
||||
|
||||
expect(() => SlashCommandAssertions.validateMaxChoicesLength([])).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid options or choices THEN throw error', () => {
|
||||
expect(() => SlashCommandAssertions.validateMaxOptionsLength(null)).toThrowError();
|
||||
|
||||
expect(() => SlashCommandAssertions.validateMaxChoicesLength(null)).toThrowError();
|
||||
|
||||
// Given an array that's too big
|
||||
expect(() => SlashCommandAssertions.validateMaxOptionsLength(largeArray)).toThrowError();
|
||||
|
||||
expect(() => SlashCommandAssertions.validateMaxChoicesLength(largeArray)).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid required parameters THEN does not throw error', () => {
|
||||
expect(() =>
|
||||
SlashCommandAssertions.validateRequiredParameters(
|
||||
'owo',
|
||||
'My fancy command that totally exists, to test assertions',
|
||||
[],
|
||||
),
|
||||
).not.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('SlashCommandBuilder', () => {
|
||||
describe('Builder with no options', () => {
|
||||
test('GIVEN empty builder THEN throw error when calling toJSON', () => {
|
||||
expect(() => getBuilder().toJSON()).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid builder THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setName('example').setDescription('Example command').toJSON()).not.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Builder with simple options', () => {
|
||||
test('GIVEN valid builder with options THEN does not throw error', () => {
|
||||
expect(() =>
|
||||
getBuilder()
|
||||
.setName('example')
|
||||
.setDescription('Example command')
|
||||
.addBooleanOption((boolean) =>
|
||||
boolean.setName('iscool').setDescription('Are we cool or what?').setRequired(true),
|
||||
)
|
||||
.addChannelOption((channel) => channel.setName('iscool').setDescription('Are we cool or what?'))
|
||||
.addMentionableOption((mentionable) => mentionable.setName('iscool').setDescription('Are we cool or what?'))
|
||||
.addRoleOption((role) => role.setName('iscool').setDescription('Are we cool or what?'))
|
||||
.addUserOption((user) => user.setName('iscool').setDescription('Are we cool or what?'))
|
||||
.addIntegerOption((integer) =>
|
||||
integer
|
||||
.setName('iscool')
|
||||
.setDescription('Are we cool or what?')
|
||||
.addChoices([['Very cool', 1_000]]),
|
||||
)
|
||||
.addNumberOption((number) =>
|
||||
number
|
||||
.setName('iscool')
|
||||
.setDescription('Are we cool or what?')
|
||||
.addChoices([['Very cool', 1.5]]),
|
||||
)
|
||||
.addStringOption((string) =>
|
||||
string
|
||||
.setName('iscool')
|
||||
.setDescription('Are we cool or what?')
|
||||
.addChoices([
|
||||
['Fancy Pants', 'fp_1'],
|
||||
['Fancy Shoes', 'fs_1'],
|
||||
['The Whole shebang', 'all'],
|
||||
]),
|
||||
)
|
||||
.addIntegerOption((integer) =>
|
||||
integer.setName('iscool').setDescription('Are we cool or what?').setAutocomplete(true),
|
||||
)
|
||||
.addNumberOption((number) =>
|
||||
number.setName('iscool').setDescription('Are we cool or what?').setAutocomplete(true),
|
||||
)
|
||||
.addStringOption((string) =>
|
||||
string.setName('iscool').setDescription('Are we cool or what?').setAutocomplete(true),
|
||||
)
|
||||
.toJSON(),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with invalid autocomplete THEN does throw an error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addStringOption(getStringOption().setAutocomplete('not a boolean'))).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with both choices and autocomplete THEN does throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().addStringOption(
|
||||
// @ts-expect-error Checking if check works JS-side too
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
getStringOption().setAutocomplete(true).addChoice('Fancy Pants', 'fp_1'),
|
||||
),
|
||||
).toThrowError();
|
||||
|
||||
expect(() =>
|
||||
getBuilder().addStringOption(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
getStringOption()
|
||||
.setAutocomplete(true)
|
||||
// @ts-expect-error Checking if check works JS-side too
|
||||
.addChoices([
|
||||
['Fancy Pants', 'fp_1'],
|
||||
['Fancy Shoes', 'fs_1'],
|
||||
['The Whole shebang', 'all'],
|
||||
]),
|
||||
),
|
||||
).toThrowError();
|
||||
|
||||
expect(() =>
|
||||
getBuilder().addStringOption(
|
||||
// @ts-expect-error Checking if check works JS-side too
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
getStringOption().addChoice('Fancy Pants', 'fp_1').setAutocomplete(true),
|
||||
),
|
||||
).toThrowError();
|
||||
|
||||
expect(() => {
|
||||
const option = getStringOption();
|
||||
Reflect.set(option, 'autocomplete', true);
|
||||
Reflect.set(option, 'choices', [{ name: 'Fancy Pants', value: 'fp_1' }]);
|
||||
return option.toJSON();
|
||||
}).toThrowError();
|
||||
|
||||
expect(() => {
|
||||
const option = getNumberOption();
|
||||
Reflect.set(option, 'autocomplete', true);
|
||||
Reflect.set(option, 'choices', [{ name: 'Fancy Pants', value: 'fp_1' }]);
|
||||
return option.toJSON();
|
||||
}).toThrowError();
|
||||
|
||||
expect(() => {
|
||||
const option = getIntegerOption();
|
||||
Reflect.set(option, 'autocomplete', true);
|
||||
Reflect.set(option, 'choices', [{ name: 'Fancy Pants', value: 'fp_1' }]);
|
||||
return option.toJSON();
|
||||
}).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with valid channel options and channel_types THEN does not throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().addChannelOption(getChannelOption().addChannelType(ChannelType.GuildText)),
|
||||
).not.toThrowError();
|
||||
|
||||
expect(() => {
|
||||
getBuilder().addChannelOption(
|
||||
getChannelOption().addChannelTypes([ChannelType.GuildNews, ChannelType.GuildText]),
|
||||
);
|
||||
}).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with valid channel options and channel_types THEN does throw an error', () => {
|
||||
expect(() => getBuilder().addChannelOption(getChannelOption().addChannelType(100))).toThrowError();
|
||||
|
||||
expect(() => getBuilder().addChannelOption(getChannelOption().addChannelTypes([100, 200]))).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with invalid number min/max options THEN does throw an error', () => {
|
||||
// @ts-expect-error
|
||||
expect(() => getBuilder().addNumberOption(getNumberOption().setMaxValue('test'))).toThrowError();
|
||||
|
||||
// @ts-expect-error
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption().setMaxValue('test'))).toThrowError();
|
||||
|
||||
// @ts-expect-error
|
||||
expect(() => getBuilder().addNumberOption(getNumberOption().setMinValue('test'))).toThrowError();
|
||||
|
||||
// @ts-expect-error
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption().setMinValue('test'))).toThrowError();
|
||||
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption().setMinValue(1.5))).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a builder with valid number min/max options THEN does not throw an error', () => {
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption().setMinValue(1))).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addNumberOption(getNumberOption().setMinValue(1.5))).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption().setMaxValue(1))).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addNumberOption(getNumberOption().setMaxValue(1.5))).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN an already built builder THEN does not throw an error', () => {
|
||||
expect(() => getBuilder().addStringOption(getStringOption())).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addIntegerOption(getIntegerOption())).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addNumberOption(getNumberOption())).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addBooleanOption(getBooleanOption())).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addUserOption(getUserOption())).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addChannelOption(getChannelOption())).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addRoleOption(getRoleOption())).not.toThrowError();
|
||||
|
||||
expect(() => getBuilder().addMentionableOption(getMentionableOption())).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN no valid return for an addOption method THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(getRoleOption())).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid name THEN throw error', () => {
|
||||
expect(() => getBuilder().setName('TEST_COMMAND')).toThrowError();
|
||||
|
||||
expect(() => getBuilder().setName('ĂĂĂĂĂĂ')).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid names THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setName('hi_there')).not.toThrowError();
|
||||
|
||||
// Translation: a_command
|
||||
expect(() => getBuilder().setName('o_comandă')).not.toThrowError();
|
||||
|
||||
// Translation: thx (according to GTranslate)
|
||||
expect(() => getBuilder().setName('どうも')).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN invalid returns for builder THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(true)).toThrowError();
|
||||
|
||||
expect(() => getBuilder().addBooleanOption(null)).toThrowError();
|
||||
|
||||
expect(() => getBuilder().addBooleanOption(undefined)).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(() => SlashCommandStringOption)).toThrowError();
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addBooleanOption(() => new Collection())).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN valid builder with defaultPermission false THEN does not throw error', () => {
|
||||
expect(() => getBuilder().setName('foo').setDescription('foo').setDefaultPermission(false)).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN an option that is autocompletable and has choices, THEN setting choices to an empty array should not throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().addStringOption(getStringOption().setAutocomplete(true).setChoices([])),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN an option that is autocompletable, THEN setting choices should throw an error', () => {
|
||||
expect(() =>
|
||||
getBuilder().addStringOption(
|
||||
getStringOption()
|
||||
.setAutocomplete(true)
|
||||
.setChoices([['owo', 'uwu']]),
|
||||
),
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN an option, THEN setting choices should not throw an error', () => {
|
||||
expect(() => getBuilder().addStringOption(getStringOption().setChoices([['owo', 'uwu']]))).not.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Builder with subcommand (group) options', () => {
|
||||
test('GIVEN builder with subcommand group THEN does not throw error', () => {
|
||||
expect(() =>
|
||||
getNamedBuilder().addSubcommandGroup((group) => group.setName('group').setDescription('Group us together!')),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN builder with subcommand THEN does not throw error', () => {
|
||||
expect(() =>
|
||||
getNamedBuilder().addSubcommand((subcommand) =>
|
||||
subcommand.setName('boop').setDescription('Boops a fellow nerd (you)'),
|
||||
),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN builder with already built subcommand group THEN does not throw error', () => {
|
||||
expect(() => getNamedBuilder().addSubcommandGroup(getSubcommandGroup())).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN builder with already built subcommand THEN does not throw error', () => {
|
||||
expect(() => getNamedBuilder().addSubcommand(getSubcommand())).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN builder with already built subcommand with options THEN does not throw error', () => {
|
||||
expect(() =>
|
||||
getNamedBuilder().addSubcommand(getSubcommand().addBooleanOption(getBooleanOption())),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN builder with a subcommand that tries to add an invalid result THEN throw error', () => {
|
||||
expect(() =>
|
||||
// @ts-expect-error Checking if check works JS-side too
|
||||
getNamedBuilder().addSubcommand(getSubcommand()).addInteger(getInteger()),
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN no valid return for an addSubcommand(Group) method THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addSubcommandGroup()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addSubcommand()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getBuilder().addSubcommand(getSubcommandGroup())).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Subcommand group builder', () => {
|
||||
test('GIVEN no valid subcommand THEN throw error', () => {
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getSubcommandGroup().addSubcommand()).toThrowError();
|
||||
|
||||
// @ts-expect-error Checking if not providing anything, or an invalid return type causes an error
|
||||
expect(() => getSubcommandGroup().addSubcommand(getSubcommandGroup())).toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN a valid subcommand THEN does not throw an error', () => {
|
||||
expect(() =>
|
||||
getSubcommandGroup()
|
||||
.addSubcommand((sub) => sub.setName('sub').setDescription('Testing 123'))
|
||||
.toJSON(),
|
||||
).not.toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Subcommand builder', () => {
|
||||
test('GIVEN a valid subcommand with options THEN does not throw error', () => {
|
||||
expect(() => getSubcommand().addBooleanOption(getBooleanOption()).toJSON()).not.toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
428
packages/builders/__tests__/messages/embed.test.ts
Normal file
428
packages/builders/__tests__/messages/embed.test.ts
Normal file
@@ -0,0 +1,428 @@
|
||||
import { Embed } from '../../src';
|
||||
import type { APIEmbed } from 'discord-api-types/v9';
|
||||
|
||||
const emptyEmbed: APIEmbed = {
|
||||
author: undefined,
|
||||
color: undefined,
|
||||
description: undefined,
|
||||
fields: [],
|
||||
footer: undefined,
|
||||
image: undefined,
|
||||
provider: undefined,
|
||||
thumbnail: undefined,
|
||||
title: undefined,
|
||||
url: undefined,
|
||||
video: undefined,
|
||||
};
|
||||
|
||||
const alpha = 'abcdefghijklmnopqrstuvwxyz';
|
||||
|
||||
describe('Embed', () => {
|
||||
describe('Embed getters', () => {
|
||||
test('GIVEN an embed with specific amount of characters THEN returns amount of characters', () => {
|
||||
const embed = new Embed({
|
||||
title: alpha,
|
||||
description: alpha,
|
||||
fields: [{ name: alpha, value: alpha }],
|
||||
author: { name: alpha },
|
||||
footer: { text: alpha },
|
||||
});
|
||||
|
||||
expect(embed.length).toBe(alpha.length * 6);
|
||||
});
|
||||
|
||||
test('GIVEN an embed with zero characters THEN returns amount of characters', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(embed.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed title', () => {
|
||||
test('GIVEN an embed with a pre-defined title THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ title: 'foo' });
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, title: 'foo' });
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setTitle THEN return valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setTitle('foo');
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, title: 'foo' });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined title THEN unset title THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ title: 'foo' });
|
||||
embed.setTitle(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid title THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(() => embed.setTitle('a'.repeat(257))).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed description', () => {
|
||||
test('GIVEN an embed with a pre-defined description THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ ...emptyEmbed, description: 'foo' });
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, description: 'foo' });
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setDescription THEN return valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setDescription('foo');
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, description: 'foo' });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined description THEN unset description THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ description: 'foo' });
|
||||
embed.setDescription(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid description THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(() => embed.setDescription('a'.repeat(4097))).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed URL', () => {
|
||||
test('GIVEN an embed with a pre-defined url THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({ url: 'https://discord.js.org/' });
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
url: 'https://discord.js.org/',
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setURL THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setURL('https://discord.js.org/');
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
url: 'https://discord.js.org/',
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined title THEN unset title THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ url: 'https://discord.js.org' });
|
||||
embed.setURL(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid URL THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(() => embed.setURL('owo')).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed Color', () => {
|
||||
test('GIVEN an embed with a pre-defined color THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({ color: 0xff0000 });
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, color: 0xff0000 });
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setColor THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setColor(0xff0000);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, color: 0xff0000 });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined color THEN unset color THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ color: 0xff0000 });
|
||||
embed.setColor(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid color THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
// @ts-expect-error
|
||||
expect(() => embed.setColor('RED')).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed Timestamp', () => {
|
||||
const now = new Date();
|
||||
|
||||
test('GIVEN an embed with a pre-defined timestamp THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({ timestamp: now.toISOString() });
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, timestamp: now.toISOString() });
|
||||
});
|
||||
|
||||
test('given an embed using Embed#setTimestamp (with Date) THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setTimestamp(now);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, timestamp: now.toISOString() });
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setTimestamp (with int) THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setTimestamp(now.getTime());
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, timestamp: now.toISOString() });
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setTimestamp (default) THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setTimestamp();
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, timestamp: embed.timestamp });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined timestamp THEN unset timestamp THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ timestamp: now.toISOString() });
|
||||
embed.setTimestamp(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed, timestamp: undefined });
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed Thumbnail', () => {
|
||||
test('GIVEN an embed with a pre-defined thumbnail THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({ thumbnail: { url: 'https://discord.js.org/static/logo.svg' } });
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
thumbnail: { url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setThumbnail THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setThumbnail('https://discord.js.org/static/logo.svg');
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
thumbnail: { url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined thumbnail THEN unset thumbnail THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ thumbnail: { url: 'https://discord.js.org/static/logo.svg' } });
|
||||
embed.setThumbnail(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid thumbnail THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(() => embed.setThumbnail('owo')).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed Image', () => {
|
||||
test('GIVEN an embed with a pre-defined image THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({ image: { url: 'https://discord.js.org/static/logo.svg' } });
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
image: { url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setImage THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setImage('https://discord.js.org/static/logo.svg');
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
image: { url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined image THEN unset image THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ image: { url: 'https://discord.js/org/static/logo.svg' } });
|
||||
embed.setImage(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid image THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(() => embed.setImage('owo')).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed Author', () => {
|
||||
test('GIVEN an embed with a pre-defined author THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({
|
||||
author: { name: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg', url: 'https://discord.js.org' },
|
||||
});
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
author: { name: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg', url: 'https://discord.js.org' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setAuthor THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setAuthor({
|
||||
name: 'Wumpus',
|
||||
iconURL: 'https://discord.js.org/static/logo.svg',
|
||||
url: 'https://discord.js.org',
|
||||
});
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
author: { name: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg', url: 'https://discord.js.org' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined author THEN unset author THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({
|
||||
author: { name: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg', url: 'https://discord.js.org' },
|
||||
});
|
||||
embed.setAuthor(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with an invalid author name THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(() => embed.setAuthor({ name: 'a'.repeat(257) })).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed Footer', () => {
|
||||
test('GIVEN an embed with a pre-defined footer THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({
|
||||
footer: { text: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
footer: { text: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#setAuthor THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.setFooter({ text: 'Wumpus', iconURL: 'https://discord.js.org/static/logo.svg' });
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
footer: { text: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg' },
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed with a pre-defined footer THEN unset footer THEN return valid toJSON data', () => {
|
||||
const embed = new Embed({ footer: { text: 'Wumpus', icon_url: 'https://discord.js.org/static/logo.svg' } });
|
||||
embed.setFooter(null);
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({ ...emptyEmbed });
|
||||
});
|
||||
|
||||
test('GIVEN an embed with invalid footer text THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(() => embed.setFooter({ text: 'a'.repeat(2049) })).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Embed Fields', () => {
|
||||
test('GIVEN an embed with a pre-defined field THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed({
|
||||
fields: [{ name: 'foo', value: 'bar', inline: undefined }],
|
||||
});
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
fields: [{ name: 'foo', value: 'bar', inline: undefined }],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#addField THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.addField({ name: 'foo', value: 'bar' });
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
fields: [{ name: 'foo', value: 'bar', inline: undefined }],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#addFields THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.addFields({ name: 'foo', value: 'bar' });
|
||||
|
||||
expect(embed.toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
fields: [{ name: 'foo', value: 'bar', inline: undefined }],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#spliceFields THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.addFields({ name: 'foo', value: 'bar' }, { name: 'foo', value: 'baz' });
|
||||
|
||||
expect(embed.spliceFields(0, 1).toJSON()).toStrictEqual({
|
||||
...emptyEmbed,
|
||||
fields: [{ name: 'foo', value: 'baz', inline: undefined }],
|
||||
});
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#spliceFields THEN returns valid toJSON data', () => {
|
||||
const embed = new Embed();
|
||||
embed.addFields(...Array.from({ length: 23 }, () => ({ name: 'foo', value: 'bar' })));
|
||||
|
||||
expect(() =>
|
||||
embed.spliceFields(0, 3, ...Array.from({ length: 5 }, () => ({ name: 'foo', value: 'bar' }))),
|
||||
).not.toThrowError();
|
||||
});
|
||||
|
||||
test('GIVEN an embed using Embed#spliceFields that adds additional fields resulting in fields > 25 THEN throws error', () => {
|
||||
const embed = new Embed();
|
||||
embed.addFields(...Array.from({ length: 23 }, () => ({ name: 'foo', value: 'bar' })));
|
||||
|
||||
expect(() =>
|
||||
embed.spliceFields(0, 3, ...Array.from({ length: 8 }, () => ({ name: 'foo', value: 'bar' }))),
|
||||
).toThrowError();
|
||||
});
|
||||
|
||||
describe('GIVEN invalid field amount THEN throws error', () => {
|
||||
test('', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(() =>
|
||||
embed.addFields(...Array.from({ length: 26 }, () => ({ name: 'foo', value: 'bar' }))),
|
||||
).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('GIVEN invalid field name THEN throws error', () => {
|
||||
test('', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(() => embed.addFields({ name: '', value: 'bar' })).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('GIVEN invalid field name length THEN throws error', () => {
|
||||
test('', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(() => embed.addFields({ name: 'a'.repeat(257), value: 'bar' })).toThrowError();
|
||||
});
|
||||
});
|
||||
|
||||
describe('GIVEN invalid field value length THEN throws error', () => {
|
||||
test('', () => {
|
||||
const embed = new Embed();
|
||||
|
||||
expect(() => embed.addFields({ name: '', value: 'a'.repeat(1025) })).toThrowError();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
206
packages/builders/__tests__/messages/formatters.test.ts
Normal file
206
packages/builders/__tests__/messages/formatters.test.ts
Normal file
@@ -0,0 +1,206 @@
|
||||
import {
|
||||
blockQuote,
|
||||
bold,
|
||||
channelMention,
|
||||
codeBlock,
|
||||
Faces,
|
||||
formatEmoji,
|
||||
hideLinkEmbed,
|
||||
hyperlink,
|
||||
inlineCode,
|
||||
italic,
|
||||
memberNicknameMention,
|
||||
quote,
|
||||
roleMention,
|
||||
spoiler,
|
||||
strikethrough,
|
||||
time,
|
||||
TimestampStyles,
|
||||
underscore,
|
||||
userMention,
|
||||
} from '../../src';
|
||||
|
||||
describe('Message formatters', () => {
|
||||
describe('codeBlock', () => {
|
||||
test('GIVEN "discord.js" with no language THEN returns "```\\ndiscord.js```"', () => {
|
||||
expect<'```\ndiscord.js```'>(codeBlock('discord.js')).toBe('```\ndiscord.js```');
|
||||
});
|
||||
|
||||
test('GIVEN "discord.js" with "js" as language THEN returns "```js\\ndiscord.js```"', () => {
|
||||
expect<'```js\ndiscord.js```'>(codeBlock('js', 'discord.js')).toBe('```js\ndiscord.js```');
|
||||
});
|
||||
});
|
||||
|
||||
describe('inlineCode', () => {
|
||||
test('GIVEN "discord.js" THEN returns "`discord.js`"', () => {
|
||||
expect<'`discord.js`'>(inlineCode('discord.js')).toBe('`discord.js`');
|
||||
});
|
||||
});
|
||||
|
||||
describe('italic', () => {
|
||||
test('GIVEN "discord.js" THEN returns "_discord.js_"', () => {
|
||||
expect<'_discord.js_'>(italic('discord.js')).toBe('_discord.js_');
|
||||
});
|
||||
});
|
||||
|
||||
describe('bold', () => {
|
||||
test('GIVEN "discord.js" THEN returns "**discord.js**"', () => {
|
||||
expect<'**discord.js**'>(bold('discord.js')).toBe('**discord.js**');
|
||||
});
|
||||
});
|
||||
|
||||
describe('underscore', () => {
|
||||
test('GIVEN "discord.js" THEN returns "__discord.js__"', () => {
|
||||
expect<'__discord.js__'>(underscore('discord.js')).toBe('__discord.js__');
|
||||
});
|
||||
});
|
||||
|
||||
describe('strikethrough', () => {
|
||||
test('GIVEN "discord.js" THEN returns "~~discord.js~~"', () => {
|
||||
expect<'~~discord.js~~'>(strikethrough('discord.js')).toBe('~~discord.js~~');
|
||||
});
|
||||
});
|
||||
|
||||
describe('quote', () => {
|
||||
test('GIVEN "discord.js" THEN returns "> discord.js"', () => {
|
||||
expect<'> discord.js'>(quote('discord.js')).toBe('> discord.js');
|
||||
});
|
||||
});
|
||||
|
||||
describe('blockQuote', () => {
|
||||
test('GIVEN "discord.js" THEN returns ">>> discord.js"', () => {
|
||||
expect<'>>> discord.js'>(blockQuote('discord.js')).toBe('>>> discord.js');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hideLinkEmbed', () => {
|
||||
test('GIVEN "https://discord.js.org" THEN returns "<https://discord.js.org>"', () => {
|
||||
expect<'<https://discord.js.org>'>(hideLinkEmbed('https://discord.js.org')).toBe('<https://discord.js.org>');
|
||||
});
|
||||
|
||||
test('GIVEN new URL("https://discord.js.org") THEN returns "<https://discord.js.org>"', () => {
|
||||
expect<`<${string}>`>(hideLinkEmbed(new URL('https://discord.js.org/'))).toBe('<https://discord.js.org/>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hyperlink', () => {
|
||||
test('GIVEN content and string URL THEN returns "[content](url)"', () => {
|
||||
expect<'[discord.js](https://discord.js.org)'>(hyperlink('discord.js', 'https://discord.js.org')).toBe(
|
||||
'[discord.js](https://discord.js.org)',
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN content and URL THEN returns "[content](url)"', () => {
|
||||
expect<`[discord.js](${string})`>(hyperlink('discord.js', new URL('https://discord.js.org'))).toBe(
|
||||
'[discord.js](https://discord.js.org/)',
|
||||
);
|
||||
});
|
||||
|
||||
test('GIVEN content, string URL, and title THEN returns "[content](url "title")"', () => {
|
||||
expect<'[discord.js](https://discord.js.org "Official Documentation")'>(
|
||||
hyperlink('discord.js', 'https://discord.js.org', 'Official Documentation'),
|
||||
).toBe('[discord.js](https://discord.js.org "Official Documentation")');
|
||||
});
|
||||
|
||||
test('GIVEN content, URL, and title THEN returns "[content](url "title")"', () => {
|
||||
expect<`[discord.js](${string} "Official Documentation")`>(
|
||||
hyperlink('discord.js', new URL('https://discord.js.org'), 'Official Documentation'),
|
||||
).toBe('[discord.js](https://discord.js.org/ "Official Documentation")');
|
||||
});
|
||||
});
|
||||
|
||||
describe('spoiler', () => {
|
||||
test('GIVEN "discord.js" THEN returns "||discord.js||"', () => {
|
||||
expect<'||discord.js||'>(spoiler('discord.js')).toBe('||discord.js||');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Mentions', () => {
|
||||
describe('userMention', () => {
|
||||
test('GIVEN userId THEN returns "<@[userId]>"', () => {
|
||||
expect(userMention('139836912335716352')).toBe('<@139836912335716352>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('memberNicknameMention', () => {
|
||||
test('GIVEN memberId THEN returns "<@![memberId]>"', () => {
|
||||
expect(memberNicknameMention('139836912335716352')).toBe('<@!139836912335716352>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('channelMention', () => {
|
||||
test('GIVEN channelId THEN returns "<#[channelId]>"', () => {
|
||||
expect(channelMention('829924760309334087')).toBe('<#829924760309334087>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('roleMention', () => {
|
||||
test('GIVEN roleId THEN returns "<&[roleId]>"', () => {
|
||||
expect(roleMention('815434166602170409')).toBe('<@&815434166602170409>');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatEmoji', () => {
|
||||
test('GIVEN static emojiId THEN returns "<:_:${emojiId}>"', () => {
|
||||
expect<`<:_:851461487498493952>`>(formatEmoji('851461487498493952')).toBe('<:_:851461487498493952>');
|
||||
});
|
||||
|
||||
test('GIVEN static emojiId WITH animated explicitly false THEN returns "<:_:[emojiId]>"', () => {
|
||||
expect<`<:_:851461487498493952>`>(formatEmoji('851461487498493952', false)).toBe('<:_:851461487498493952>');
|
||||
});
|
||||
|
||||
test('GIVEN animated emojiId THEN returns "<a:_:${emojiId}>"', () => {
|
||||
expect<`<a:_:827220205352255549>`>(formatEmoji('827220205352255549', true)).toBe('<a:_:827220205352255549>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('time', () => {
|
||||
test('GIVEN no arguments THEN returns "<t:${bigint}>"', () => {
|
||||
jest.useFakeTimers('modern');
|
||||
jest.setSystemTime(1566424897579);
|
||||
|
||||
expect<`<t:${bigint}>`>(time()).toBe('<t:1566424897>');
|
||||
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
test('GIVEN a date THEN returns "<t:${bigint}>"', () => {
|
||||
expect<`<t:${bigint}>`>(time(new Date(1867424897579))).toBe('<t:1867424897>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a style from string THEN returns "<t:${bigint}:${style}>"', () => {
|
||||
expect<`<t:${bigint}:d>`>(time(new Date(1867424897579), 'd')).toBe('<t:1867424897:d>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a format from enum THEN returns "<t:${bigint}:${style}>"', () => {
|
||||
expect<`<t:${bigint}:R>`>(time(new Date(1867424897579), TimestampStyles.RelativeTime)).toBe('<t:1867424897:R>');
|
||||
});
|
||||
|
||||
test('GIVEN a date THEN returns "<t:${time}>"', () => {
|
||||
expect<'<t:1867424897>'>(time(1867424897)).toBe('<t:1867424897>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a style from string THEN returns "<t:${time}:${style}>"', () => {
|
||||
expect<'<t:1867424897:d>'>(time(1867424897, 'd')).toBe('<t:1867424897:d>');
|
||||
});
|
||||
|
||||
test('GIVEN a date and a format from enum THEN returns "<t:${time}:${style}>"', () => {
|
||||
expect<'<t:1867424897:R>'>(time(1867424897, TimestampStyles.RelativeTime)).toBe('<t:1867424897:R>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Faces', () => {
|
||||
test('GIVEN Faces.Shrug THEN returns "¯\\_(ツ)\\_/¯"', () => {
|
||||
expect<'¯\\_(ツ)\\_/¯'>(Faces.Shrug).toBe('¯\\_(ツ)\\_/¯');
|
||||
});
|
||||
|
||||
test('GIVEN Faces.Tableflip THEN returns "(╯°□°)╯︵ ┻━┻"', () => {
|
||||
expect<'(╯°□°)╯︵ ┻━┻'>(Faces.Tableflip).toBe('(╯°□°)╯︵ ┻━┻');
|
||||
});
|
||||
|
||||
test('GIVEN Faces.Unflip THEN returns "┬─┬ ノ( ゜-゜ノ)"', () => {
|
||||
expect<'┬─┬ ノ( ゜-゜ノ)'>(Faces.Unflip).toBe('┬─┬ ノ( ゜-゜ノ)');
|
||||
});
|
||||
});
|
||||
});
|
||||
18
packages/builders/babel.config.js
Normal file
18
packages/builders/babel.config.js
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* @type {import('@babel/core').TransformOptions}
|
||||
*/
|
||||
module.exports = {
|
||||
parserOpts: { strictMode: true },
|
||||
sourceMaps: 'inline',
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: { node: 'current' },
|
||||
modules: 'commonjs',
|
||||
},
|
||||
],
|
||||
'@babel/preset-typescript',
|
||||
],
|
||||
plugins: ['babel-plugin-transform-typescript-metadata', ['@babel/plugin-proposal-decorators', { legacy: true }]],
|
||||
};
|
||||
10
packages/builders/codecov.yml
Normal file
10
packages/builders/codecov.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
coverage:
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
target: 70%
|
||||
threshold: 5%
|
||||
patch:
|
||||
default:
|
||||
target: 70%
|
||||
threshold: 5%
|
||||
1
packages/builders/docs/README.md
Normal file
1
packages/builders/docs/README.md
Normal file
@@ -0,0 +1 @@
|
||||
## [View the documentation here.](https://discord.js.org/#/docs/builders)
|
||||
5
packages/builders/docs/index.yml
Normal file
5
packages/builders/docs/index.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
- name: General
|
||||
files:
|
||||
- name: Welcome
|
||||
id: welcome
|
||||
path: ../../README.md
|
||||
19
packages/builders/jest.config.js
Normal file
19
packages/builders/jest.config.js
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @type {import('@jest/types').Config.InitialOptions}
|
||||
*/
|
||||
module.exports = {
|
||||
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
|
||||
testEnvironment: 'node',
|
||||
collectCoverage: true,
|
||||
collectCoverageFrom: ['src/**/*.ts'],
|
||||
coverageDirectory: 'coverage',
|
||||
coverageReporters: ['text', 'lcov', 'clover'],
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
branches: 70,
|
||||
lines: 70,
|
||||
statements: 70,
|
||||
},
|
||||
},
|
||||
coveragePathIgnorePatterns: ['src/index.ts'],
|
||||
};
|
||||
88
packages/builders/package.json
Normal file
88
packages/builders/package.json
Normal file
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"name": "@discordjs/builders",
|
||||
"version": "0.11.0",
|
||||
"description": "A set of builders that you can use when creating your bot",
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"test": "jest --pass-with-no-tests",
|
||||
"lint": "eslint src --ext mjs,js,ts",
|
||||
"lint:fix": "eslint src --ext mjs,js,ts --fix",
|
||||
"format": "prettier --write **/*.{ts,js,json,yml,yaml}",
|
||||
"docs": "typedoc --json docs/typedoc-out.json src/index.ts && node scripts/docs.mjs",
|
||||
"prepublishOnly": "yarn build && yarn lint && yarn test",
|
||||
"changelog": "git cliff --prepend ./CHANGELOG.md -l -c ../../cliff.toml -r ../../ --include-path './*'"
|
||||
},
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.js"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "src",
|
||||
"test": "__tests__"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"contributors": [
|
||||
"Vlad Frangu <kingdgrizzle@gmail.com>",
|
||||
"Crawl <icrawltogo@gmail.com>",
|
||||
"Amish Shah <amishshah.2k@gmail.com>",
|
||||
"SpaceEEC <spaceeec@yahoo.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"discord",
|
||||
"api",
|
||||
"bot",
|
||||
"client",
|
||||
"node",
|
||||
"discordapp",
|
||||
"discordjs"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/discordjs/discord.js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"dependencies": {
|
||||
"@sindresorhus/is": "^4.2.0",
|
||||
"discord-api-types": "^0.26.0",
|
||||
"ts-mixer": "^6.0.0",
|
||||
"tslib": "^2.3.1",
|
||||
"zod": "^3.11.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.16.5",
|
||||
"@babel/plugin-proposal-decorators": "^7.16.5",
|
||||
"@babel/preset-env": "^7.16.5",
|
||||
"@babel/preset-typescript": "^7.16.5",
|
||||
"@discordjs/ts-docgen": "^0.3.4",
|
||||
"@types/jest": "^27.0.3",
|
||||
"@types/node": "^16.11.6",
|
||||
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
||||
"@typescript-eslint/parser": "^5.8.0",
|
||||
"babel-plugin-transform-typescript-metadata": "^0.3.2",
|
||||
"eslint": "^8.5.0",
|
||||
"eslint-config-marine": "^9.1.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"jest": "^27.4.5",
|
||||
"prettier": "^2.5.1",
|
||||
"standard-version": "^9.3.2",
|
||||
"tsup": "^5.11.8",
|
||||
"typedoc": "^0.22.10",
|
||||
"typescript": "^4.5.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
||||
7
packages/builders/scripts/docs.mjs
Normal file
7
packages/builders/scripts/docs.mjs
Normal file
@@ -0,0 +1,7 @@
|
||||
import { runGenerator } from '@discordjs/ts-docgen';
|
||||
|
||||
runGenerator({
|
||||
existingOutput: 'docs/typedoc-out.json',
|
||||
custom: 'docs/index.yml',
|
||||
output: 'docs/docs.json',
|
||||
});
|
||||
18
packages/builders/src/index.ts
Normal file
18
packages/builders/src/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export * as EmbedAssertions from './messages/embed/Assertions';
|
||||
export * from './messages/embed/Embed';
|
||||
export * from './messages/formatters';
|
||||
|
||||
export * as SlashCommandAssertions from './interactions/slashCommands/Assertions';
|
||||
export * from './interactions/slashCommands/SlashCommandBuilder';
|
||||
export * from './interactions/slashCommands/SlashCommandSubcommands';
|
||||
export * from './interactions/slashCommands/options/boolean';
|
||||
export * from './interactions/slashCommands/options/channel';
|
||||
export * from './interactions/slashCommands/options/integer';
|
||||
export * from './interactions/slashCommands/options/mentionable';
|
||||
export * from './interactions/slashCommands/options/number';
|
||||
export * from './interactions/slashCommands/options/role';
|
||||
export * from './interactions/slashCommands/options/string';
|
||||
export * from './interactions/slashCommands/options/user';
|
||||
|
||||
export * as ContextMenuCommandAssertions from './interactions/contextMenuCommands/Assertions';
|
||||
export * from './interactions/contextMenuCommands/ContextMenuCommandBuilder';
|
||||
@@ -0,0 +1,33 @@
|
||||
import { z } from 'zod';
|
||||
import { ApplicationCommandType } from 'discord-api-types/v9';
|
||||
import type { ContextMenuCommandType } from './ContextMenuCommandBuilder';
|
||||
|
||||
export function validateRequiredParameters(name: string, type: number) {
|
||||
// Assert name matches all conditions
|
||||
validateName(name);
|
||||
|
||||
// Assert type is valid
|
||||
validateType(type);
|
||||
}
|
||||
|
||||
const namePredicate = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(32)
|
||||
.regex(/^( *[\p{L}\p{N}_-]+ *)+$/u);
|
||||
|
||||
export function validateName(name: unknown): asserts name is string {
|
||||
namePredicate.parse(name);
|
||||
}
|
||||
|
||||
const typePredicate = z.union([z.literal(ApplicationCommandType.User), z.literal(ApplicationCommandType.Message)]);
|
||||
|
||||
export function validateType(type: unknown): asserts type is ContextMenuCommandType {
|
||||
typePredicate.parse(type);
|
||||
}
|
||||
|
||||
const booleanPredicate = z.boolean();
|
||||
|
||||
export function validateDefaultPermission(value: unknown): asserts value is boolean {
|
||||
booleanPredicate.parse(value);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import { validateRequiredParameters, validateName, validateType, validateDefaultPermission } from './Assertions';
|
||||
import type { ApplicationCommandType, RESTPostAPIApplicationCommandsJSONBody } from 'discord-api-types/v9';
|
||||
|
||||
export class ContextMenuCommandBuilder {
|
||||
/**
|
||||
* The name of this context menu command
|
||||
*/
|
||||
public readonly name: string = undefined!;
|
||||
|
||||
/**
|
||||
* The type of this context menu command
|
||||
*/
|
||||
public readonly type: ContextMenuCommandType = undefined!;
|
||||
|
||||
/**
|
||||
* Whether the command is enabled by default when the app is added to a guild
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
public readonly defaultPermission: boolean | undefined = undefined;
|
||||
|
||||
/**
|
||||
* Sets the name
|
||||
*
|
||||
* @param name The name
|
||||
*/
|
||||
public setName(name: string) {
|
||||
// Assert the name matches the conditions
|
||||
validateName(name);
|
||||
|
||||
Reflect.set(this, 'name', name);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type
|
||||
*
|
||||
* @param type The type
|
||||
*/
|
||||
public setType(type: ContextMenuCommandType) {
|
||||
// Assert the type is valid
|
||||
validateType(type);
|
||||
|
||||
Reflect.set(this, 'type', type);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the command is enabled by default when the application is added to a guild.
|
||||
*
|
||||
* **Note**: If set to `false`, you will have to later `PUT` the permissions for this command.
|
||||
*
|
||||
* @param value Whether or not to enable this command by default
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
*/
|
||||
public setDefaultPermission(value: boolean) {
|
||||
// Assert the value matches the conditions
|
||||
validateDefaultPermission(value);
|
||||
|
||||
Reflect.set(this, 'defaultPermission', value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the final data that should be sent to Discord.
|
||||
*
|
||||
* **Note:** Calling this function will validate required properties based on their conditions.
|
||||
*/
|
||||
public toJSON(): RESTPostAPIApplicationCommandsJSONBody {
|
||||
validateRequiredParameters(this.name, this.type);
|
||||
return {
|
||||
name: this.name,
|
||||
type: this.type,
|
||||
default_permission: this.defaultPermission,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export type ContextMenuCommandType = ApplicationCommandType.User | ApplicationCommandType.Message;
|
||||
@@ -0,0 +1,84 @@
|
||||
import is from '@sindresorhus/is';
|
||||
import type { APIApplicationCommandOptionChoice } from 'discord-api-types/v9';
|
||||
import { z } from 'zod';
|
||||
import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase';
|
||||
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder';
|
||||
import type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands';
|
||||
|
||||
export function validateRequiredParameters(
|
||||
name: string,
|
||||
description: string,
|
||||
options: ToAPIApplicationCommandOptions[],
|
||||
) {
|
||||
// Assert name matches all conditions
|
||||
validateName(name);
|
||||
|
||||
// Assert description conditions
|
||||
validateDescription(description);
|
||||
|
||||
// Assert options conditions
|
||||
validateMaxOptionsLength(options);
|
||||
}
|
||||
|
||||
const namePredicate = z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(32)
|
||||
.regex(/^[\P{Lu}\p{N}_-]+$/u);
|
||||
|
||||
export function validateName(name: unknown): asserts name is string {
|
||||
namePredicate.parse(name);
|
||||
}
|
||||
|
||||
const descriptionPredicate = z.string().min(1).max(100);
|
||||
|
||||
export function validateDescription(description: unknown): asserts description is string {
|
||||
descriptionPredicate.parse(description);
|
||||
}
|
||||
|
||||
const booleanPredicate = z.boolean();
|
||||
|
||||
export function validateDefaultPermission(value: unknown): asserts value is boolean {
|
||||
booleanPredicate.parse(value);
|
||||
}
|
||||
|
||||
export function validateRequired(required: unknown): asserts required is boolean {
|
||||
booleanPredicate.parse(required);
|
||||
}
|
||||
|
||||
const maxArrayLengthPredicate = z.unknown().array().max(25);
|
||||
|
||||
export function validateMaxOptionsLength(options: unknown): asserts options is ToAPIApplicationCommandOptions[] {
|
||||
maxArrayLengthPredicate.parse(options);
|
||||
}
|
||||
|
||||
export function validateMaxChoicesLength(choices: APIApplicationCommandOptionChoice[]) {
|
||||
maxArrayLengthPredicate.parse(choices);
|
||||
}
|
||||
|
||||
export function assertReturnOfBuilder<
|
||||
T extends ApplicationCommandOptionBase | SlashCommandSubcommandBuilder | SlashCommandSubcommandGroupBuilder,
|
||||
>(input: unknown, ExpectedInstanceOf: new () => T): asserts input is T {
|
||||
const instanceName = ExpectedInstanceOf.name;
|
||||
|
||||
if (is.nullOrUndefined(input)) {
|
||||
throw new TypeError(
|
||||
`Expected to receive a ${instanceName} builder, got ${input === null ? 'null' : 'undefined'} instead.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (is.primitive(input)) {
|
||||
throw new TypeError(`Expected to receive a ${instanceName} builder, got a primitive (${typeof input}) instead.`);
|
||||
}
|
||||
|
||||
if (!(input instanceof ExpectedInstanceOf)) {
|
||||
const casted = input as Record<PropertyKey, unknown>;
|
||||
|
||||
const constructorName = is.function_(input) ? input.name : casted.constructor.name;
|
||||
const stringTag = Reflect.get(casted, Symbol.toStringTag) as string | undefined;
|
||||
|
||||
const fullResultName = stringTag ? `${constructorName} [${stringTag}]` : constructorName;
|
||||
|
||||
throw new TypeError(`Expected to receive a ${instanceName} builder, got ${fullResultName} instead.`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import type { APIApplicationCommandOption, RESTPostAPIApplicationCommandsJSONBody } from 'discord-api-types/v9';
|
||||
import { mix } from 'ts-mixer';
|
||||
import {
|
||||
assertReturnOfBuilder,
|
||||
validateDefaultPermission,
|
||||
validateMaxOptionsLength,
|
||||
validateRequiredParameters,
|
||||
} from './Assertions';
|
||||
import { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions';
|
||||
import { SharedNameAndDescription } from './mixins/NameAndDescription';
|
||||
import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands';
|
||||
|
||||
@mix(SharedSlashCommandOptions, SharedNameAndDescription)
|
||||
export class SlashCommandBuilder {
|
||||
/**
|
||||
* The name of this slash command
|
||||
*/
|
||||
public readonly name: string = undefined!;
|
||||
|
||||
/**
|
||||
* The description of this slash command
|
||||
*/
|
||||
public readonly description: string = undefined!;
|
||||
|
||||
/**
|
||||
* The options of this slash command
|
||||
*/
|
||||
public readonly options: ToAPIApplicationCommandOptions[] = [];
|
||||
|
||||
/**
|
||||
* Whether the command is enabled by default when the app is added to a guild
|
||||
*
|
||||
* @default true
|
||||
*/
|
||||
public readonly defaultPermission: boolean | undefined = undefined;
|
||||
|
||||
/**
|
||||
* Returns the final data that should be sent to Discord.
|
||||
*
|
||||
* **Note:** Calling this function will validate required properties based on their conditions.
|
||||
*/
|
||||
public toJSON(): RESTPostAPIApplicationCommandsJSONBody {
|
||||
validateRequiredParameters(this.name, this.description, this.options);
|
||||
|
||||
return {
|
||||
name: this.name,
|
||||
description: this.description,
|
||||
options: this.options.map((option) => option.toJSON()),
|
||||
default_permission: this.defaultPermission,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the command is enabled by default when the application is added to a guild.
|
||||
*
|
||||
* **Note**: If set to `false`, you will have to later `PUT` the permissions for this command.
|
||||
*
|
||||
* @param value Whether or not to enable this command by default
|
||||
*
|
||||
* @see https://discord.com/developers/docs/interactions/application-commands#permissions
|
||||
*/
|
||||
public setDefaultPermission(value: boolean) {
|
||||
// Assert the value matches the conditions
|
||||
validateDefaultPermission(value);
|
||||
|
||||
Reflect.set(this, 'defaultPermission', value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new subcommand group to this command
|
||||
*
|
||||
* @param input A function that returns a subcommand group builder, or an already built builder
|
||||
*/
|
||||
public addSubcommandGroup(
|
||||
input:
|
||||
| SlashCommandSubcommandGroupBuilder
|
||||
| ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder),
|
||||
): SlashCommandSubcommandsOnlyBuilder {
|
||||
const { options } = this;
|
||||
|
||||
// First, assert options conditions - we cannot have more than 25 options
|
||||
validateMaxOptionsLength(options);
|
||||
|
||||
// Get the final result
|
||||
const result = typeof input === 'function' ? input(new SlashCommandSubcommandGroupBuilder()) : input;
|
||||
|
||||
assertReturnOfBuilder(result, SlashCommandSubcommandGroupBuilder);
|
||||
|
||||
// Push it
|
||||
options.push(result);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new subcommand to this command
|
||||
*
|
||||
* @param input A function that returns a subcommand builder, or an already built builder
|
||||
*/
|
||||
public addSubcommand(
|
||||
input:
|
||||
| SlashCommandSubcommandBuilder
|
||||
| ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder),
|
||||
): SlashCommandSubcommandsOnlyBuilder {
|
||||
const { options } = this;
|
||||
|
||||
// First, assert options conditions - we cannot have more than 25 options
|
||||
validateMaxOptionsLength(options);
|
||||
|
||||
// Get the final result
|
||||
const result = typeof input === 'function' ? input(new SlashCommandSubcommandBuilder()) : input;
|
||||
|
||||
assertReturnOfBuilder(result, SlashCommandSubcommandBuilder);
|
||||
|
||||
// Push it
|
||||
options.push(result);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SlashCommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions {}
|
||||
|
||||
export interface SlashCommandSubcommandsOnlyBuilder
|
||||
extends SharedNameAndDescription,
|
||||
Pick<SlashCommandBuilder, 'toJSON' | 'addSubcommand' | 'addSubcommandGroup'> {}
|
||||
|
||||
export interface SlashCommandOptionsOnlyBuilder
|
||||
extends SharedNameAndDescription,
|
||||
SharedSlashCommandOptions,
|
||||
Pick<SlashCommandBuilder, 'toJSON'> {}
|
||||
|
||||
export interface ToAPIApplicationCommandOptions {
|
||||
toJSON(): APIApplicationCommandOption;
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import {
|
||||
APIApplicationCommandSubcommandGroupOption,
|
||||
APIApplicationCommandSubcommandOption,
|
||||
ApplicationCommandOptionType,
|
||||
} from 'discord-api-types/v9';
|
||||
import { mix } from 'ts-mixer';
|
||||
import { assertReturnOfBuilder, validateMaxOptionsLength, validateRequiredParameters } from './Assertions';
|
||||
import type { ApplicationCommandOptionBase } from './mixins/ApplicationCommandOptionBase';
|
||||
import { SharedNameAndDescription } from './mixins/NameAndDescription';
|
||||
import { SharedSlashCommandOptions } from './mixins/SharedSlashCommandOptions';
|
||||
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder';
|
||||
|
||||
/**
|
||||
* Represents a folder for subcommands
|
||||
*
|
||||
* For more information, go to https://discord.com/developers/docs/interactions/slash-commands#subcommands-and-subcommand-groups
|
||||
*/
|
||||
@mix(SharedNameAndDescription)
|
||||
export class SlashCommandSubcommandGroupBuilder implements ToAPIApplicationCommandOptions {
|
||||
/**
|
||||
* The name of this subcommand group
|
||||
*/
|
||||
public readonly name: string = undefined!;
|
||||
|
||||
/**
|
||||
* The description of this subcommand group
|
||||
*/
|
||||
public readonly description: string = undefined!;
|
||||
|
||||
/**
|
||||
* The subcommands part of this subcommand group
|
||||
*/
|
||||
public readonly options: SlashCommandSubcommandBuilder[] = [];
|
||||
|
||||
/**
|
||||
* Adds a new subcommand to this group
|
||||
*
|
||||
* @param input A function that returns a subcommand builder, or an already built builder
|
||||
*/
|
||||
public addSubcommand(
|
||||
input:
|
||||
| SlashCommandSubcommandBuilder
|
||||
| ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder),
|
||||
) {
|
||||
const { options } = this;
|
||||
|
||||
// First, assert options conditions - we cannot have more than 25 options
|
||||
validateMaxOptionsLength(options);
|
||||
|
||||
// Get the final result
|
||||
const result = typeof input === 'function' ? input(new SlashCommandSubcommandBuilder()) : input;
|
||||
|
||||
assertReturnOfBuilder(result, SlashCommandSubcommandBuilder);
|
||||
|
||||
// Push it
|
||||
options.push(result);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public toJSON(): APIApplicationCommandSubcommandGroupOption {
|
||||
validateRequiredParameters(this.name, this.description, this.options);
|
||||
|
||||
return {
|
||||
type: ApplicationCommandOptionType.SubcommandGroup,
|
||||
name: this.name,
|
||||
description: this.description,
|
||||
options: this.options.map((option) => option.toJSON()),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export interface SlashCommandSubcommandGroupBuilder extends SharedNameAndDescription {}
|
||||
|
||||
/**
|
||||
* Represents a subcommand
|
||||
*
|
||||
* For more information, go to https://discord.com/developers/docs/interactions/slash-commands#subcommands-and-subcommand-groups
|
||||
*/
|
||||
@mix(SharedNameAndDescription, SharedSlashCommandOptions)
|
||||
export class SlashCommandSubcommandBuilder implements ToAPIApplicationCommandOptions {
|
||||
/**
|
||||
* The name of this subcommand
|
||||
*/
|
||||
public readonly name: string = undefined!;
|
||||
|
||||
/**
|
||||
* The description of this subcommand
|
||||
*/
|
||||
public readonly description: string = undefined!;
|
||||
|
||||
/**
|
||||
* The options of this subcommand
|
||||
*/
|
||||
public readonly options: ApplicationCommandOptionBase[] = [];
|
||||
|
||||
public toJSON(): APIApplicationCommandSubcommandOption {
|
||||
validateRequiredParameters(this.name, this.description, this.options);
|
||||
|
||||
return {
|
||||
type: ApplicationCommandOptionType.Subcommand,
|
||||
name: this.name,
|
||||
description: this.description,
|
||||
options: this.options.map((option) => option.toJSON()),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export interface SlashCommandSubcommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions<false> {}
|
||||
@@ -0,0 +1,16 @@
|
||||
export abstract class ApplicationCommandNumericOptionMinMaxValueMixin {
|
||||
public readonly max_value?: number;
|
||||
public readonly min_value?: number;
|
||||
|
||||
/**
|
||||
* Sets the maximum number value of this option
|
||||
* @param max The maximum value this option can be
|
||||
*/
|
||||
public abstract setMaxValue(max: number): this;
|
||||
|
||||
/**
|
||||
* Sets the minimum number value of this option
|
||||
* @param min The minimum value this option can be
|
||||
*/
|
||||
public abstract setMinValue(min: number): this;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { APIApplicationCommandBasicOption, ApplicationCommandOptionType } from 'discord-api-types/v9';
|
||||
import { validateRequiredParameters, validateRequired } from '../Assertions';
|
||||
import { SharedNameAndDescription } from './NameAndDescription';
|
||||
|
||||
export abstract class ApplicationCommandOptionBase extends SharedNameAndDescription {
|
||||
public abstract readonly type: ApplicationCommandOptionType;
|
||||
|
||||
public readonly required = false;
|
||||
|
||||
/**
|
||||
* Marks the option as required
|
||||
*
|
||||
* @param required If this option should be required
|
||||
*/
|
||||
public setRequired(required: boolean) {
|
||||
// Assert that you actually passed a boolean
|
||||
validateRequired(required);
|
||||
|
||||
Reflect.set(this, 'required', required);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract toJSON(): APIApplicationCommandBasicOption;
|
||||
|
||||
protected runRequiredValidations() {
|
||||
validateRequiredParameters(this.name, this.description, []);
|
||||
|
||||
// Assert that you actually passed a boolean
|
||||
validateRequired(this.required);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { ChannelType } from 'discord-api-types/v9';
|
||||
import { z, ZodLiteral } from 'zod';
|
||||
|
||||
// Only allow valid channel types to be used. (This can't be dynamic because const enums are erased at runtime)
|
||||
const allowedChannelTypes = [
|
||||
ChannelType.GuildText,
|
||||
ChannelType.GuildVoice,
|
||||
ChannelType.GuildCategory,
|
||||
ChannelType.GuildNews,
|
||||
ChannelType.GuildStore,
|
||||
ChannelType.GuildNewsThread,
|
||||
ChannelType.GuildPublicThread,
|
||||
ChannelType.GuildPrivateThread,
|
||||
ChannelType.GuildStageVoice,
|
||||
] as const;
|
||||
|
||||
export type ApplicationCommandOptionAllowedChannelTypes = typeof allowedChannelTypes[number];
|
||||
|
||||
const channelTypePredicate = z.union(
|
||||
allowedChannelTypes.map((type) => z.literal(type)) as [
|
||||
ZodLiteral<ChannelType>,
|
||||
ZodLiteral<ChannelType>,
|
||||
...ZodLiteral<ChannelType>[]
|
||||
],
|
||||
);
|
||||
|
||||
export class ApplicationCommandOptionChannelTypesMixin {
|
||||
public readonly channel_types?: ApplicationCommandOptionAllowedChannelTypes[];
|
||||
|
||||
/**
|
||||
* Adds a channel type to this option
|
||||
*
|
||||
* @param channelType The type of channel to allow
|
||||
*/
|
||||
public addChannelType(channelType: ApplicationCommandOptionAllowedChannelTypes) {
|
||||
if (this.channel_types === undefined) {
|
||||
Reflect.set(this, 'channel_types', []);
|
||||
}
|
||||
|
||||
channelTypePredicate.parse(channelType);
|
||||
this.channel_types!.push(channelType);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds channel types to this option
|
||||
*
|
||||
* @param channelTypes The channel types to add
|
||||
*/
|
||||
public addChannelTypes(channelTypes: ApplicationCommandOptionAllowedChannelTypes[]) {
|
||||
channelTypes.forEach((channelType) => this.addChannelType(channelType));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import { APIApplicationCommandOptionChoice, ApplicationCommandOptionType } from 'discord-api-types/v9';
|
||||
import { z } from 'zod';
|
||||
import { validateMaxChoicesLength } from '../Assertions';
|
||||
|
||||
const stringPredicate = z.string().min(1).max(100);
|
||||
const numberPredicate = z.number().gt(-Infinity).lt(Infinity);
|
||||
const choicesPredicate = z.tuple([stringPredicate, z.union([stringPredicate, numberPredicate])]).array();
|
||||
const booleanPredicate = z.boolean();
|
||||
|
||||
export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T extends string | number> {
|
||||
public readonly choices?: APIApplicationCommandOptionChoice<T>[];
|
||||
public readonly autocomplete?: boolean;
|
||||
|
||||
// Since this is present and this is a mixin, this is needed
|
||||
public readonly type!: ApplicationCommandOptionType;
|
||||
|
||||
/**
|
||||
* Adds a choice for this option
|
||||
*
|
||||
* @param name The name of the choice
|
||||
* @param value The value of the choice
|
||||
*/
|
||||
public addChoice(name: string, value: T): Omit<this, 'setAutocomplete'> {
|
||||
if (this.autocomplete) {
|
||||
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
||||
}
|
||||
|
||||
if (this.choices === undefined) {
|
||||
Reflect.set(this, 'choices', []);
|
||||
}
|
||||
|
||||
validateMaxChoicesLength(this.choices!);
|
||||
|
||||
// Validate name
|
||||
stringPredicate.parse(name);
|
||||
|
||||
// Validate the value
|
||||
if (this.type === ApplicationCommandOptionType.String) {
|
||||
stringPredicate.parse(value);
|
||||
} else {
|
||||
numberPredicate.parse(value);
|
||||
}
|
||||
|
||||
this.choices!.push({ name, value });
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds multiple choices for this option
|
||||
*
|
||||
* @param choices The choices to add
|
||||
*/
|
||||
public addChoices(choices: [name: string, value: T][]): Omit<this, 'setAutocomplete'> {
|
||||
if (this.autocomplete) {
|
||||
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
||||
}
|
||||
|
||||
choicesPredicate.parse(choices);
|
||||
|
||||
for (const [label, value] of choices) this.addChoice(label, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public setChoices<Input extends [name: string, value: T][]>(
|
||||
choices: Input,
|
||||
): Input extends []
|
||||
? this & Pick<ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T>, 'setAutocomplete'>
|
||||
: Omit<this, 'setAutocomplete'> {
|
||||
if (choices.length > 0 && this.autocomplete) {
|
||||
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
||||
}
|
||||
|
||||
choicesPredicate.parse(choices);
|
||||
|
||||
Reflect.set(this, 'choices', []);
|
||||
for (const [label, value] of choices) this.addChoice(label, value);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the option as autocompletable
|
||||
* @param autocomplete If this option should be autocompletable
|
||||
*/
|
||||
public setAutocomplete<U extends boolean>(
|
||||
autocomplete: U,
|
||||
): U extends true
|
||||
? Omit<this, 'addChoice' | 'addChoices'>
|
||||
: this & Pick<ApplicationCommandOptionWithChoicesAndAutocompleteMixin<T>, 'addChoice' | 'addChoices'> {
|
||||
// Assert that you actually passed a boolean
|
||||
booleanPredicate.parse(autocomplete);
|
||||
|
||||
if (autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {
|
||||
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
||||
}
|
||||
|
||||
Reflect.set(this, 'autocomplete', autocomplete);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { validateDescription, validateName } from '../Assertions';
|
||||
|
||||
export class SharedNameAndDescription {
|
||||
public readonly name!: string;
|
||||
public readonly description!: string;
|
||||
|
||||
/**
|
||||
* Sets the name
|
||||
*
|
||||
* @param name The name
|
||||
*/
|
||||
public setName(name: string): this {
|
||||
// Assert the name matches the conditions
|
||||
validateName(name);
|
||||
|
||||
Reflect.set(this, 'name', name);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the description
|
||||
*
|
||||
* @param description The description
|
||||
*/
|
||||
public setDescription(description: string) {
|
||||
// Assert the description matches the conditions
|
||||
validateDescription(description);
|
||||
|
||||
Reflect.set(this, 'description', description);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
import { assertReturnOfBuilder, validateMaxOptionsLength } from '../Assertions';
|
||||
import type { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase';
|
||||
import { SlashCommandBooleanOption } from '../options/boolean';
|
||||
import { SlashCommandChannelOption } from '../options/channel';
|
||||
import { SlashCommandIntegerOption } from '../options/integer';
|
||||
import { SlashCommandMentionableOption } from '../options/mentionable';
|
||||
import { SlashCommandNumberOption } from '../options/number';
|
||||
import { SlashCommandRoleOption } from '../options/role';
|
||||
import { SlashCommandStringOption } from '../options/string';
|
||||
import { SlashCommandUserOption } from '../options/user';
|
||||
import type { ToAPIApplicationCommandOptions } from '../SlashCommandBuilder';
|
||||
|
||||
export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
|
||||
public readonly options!: ToAPIApplicationCommandOptions[];
|
||||
|
||||
/**
|
||||
* Adds a boolean option
|
||||
*
|
||||
* @param input A function that returns an option builder, or an already built builder
|
||||
*/
|
||||
public addBooleanOption(
|
||||
input: SlashCommandBooleanOption | ((builder: SlashCommandBooleanOption) => SlashCommandBooleanOption),
|
||||
) {
|
||||
return this._sharedAddOptionMethod(input, SlashCommandBooleanOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a user option
|
||||
*
|
||||
* @param input A function that returns an option builder, or an already built builder
|
||||
*/
|
||||
public addUserOption(input: SlashCommandUserOption | ((builder: SlashCommandUserOption) => SlashCommandUserOption)) {
|
||||
return this._sharedAddOptionMethod(input, SlashCommandUserOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a channel option
|
||||
*
|
||||
* @param input A function that returns an option builder, or an already built builder
|
||||
*/
|
||||
public addChannelOption(
|
||||
input: SlashCommandChannelOption | ((builder: SlashCommandChannelOption) => SlashCommandChannelOption),
|
||||
) {
|
||||
return this._sharedAddOptionMethod(input, SlashCommandChannelOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a role option
|
||||
*
|
||||
* @param input A function that returns an option builder, or an already built builder
|
||||
*/
|
||||
public addRoleOption(input: SlashCommandRoleOption | ((builder: SlashCommandRoleOption) => SlashCommandRoleOption)) {
|
||||
return this._sharedAddOptionMethod(input, SlashCommandRoleOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a mentionable option
|
||||
*
|
||||
* @param input A function that returns an option builder, or an already built builder
|
||||
*/
|
||||
public addMentionableOption(
|
||||
input: SlashCommandMentionableOption | ((builder: SlashCommandMentionableOption) => SlashCommandMentionableOption),
|
||||
) {
|
||||
return this._sharedAddOptionMethod(input, SlashCommandMentionableOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a string option
|
||||
*
|
||||
* @param input A function that returns an option builder, or an already built builder
|
||||
*/
|
||||
public addStringOption(
|
||||
input:
|
||||
| SlashCommandStringOption
|
||||
| Omit<SlashCommandStringOption, 'setAutocomplete'>
|
||||
| Omit<SlashCommandStringOption, 'addChoice' | 'addChoices'>
|
||||
| ((
|
||||
builder: SlashCommandStringOption,
|
||||
) =>
|
||||
| SlashCommandStringOption
|
||||
| Omit<SlashCommandStringOption, 'setAutocomplete'>
|
||||
| Omit<SlashCommandStringOption, 'addChoice' | 'addChoices'>),
|
||||
) {
|
||||
return this._sharedAddOptionMethod(input, SlashCommandStringOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an integer option
|
||||
*
|
||||
* @param input A function that returns an option builder, or an already built builder
|
||||
*/
|
||||
public addIntegerOption(
|
||||
input:
|
||||
| SlashCommandIntegerOption
|
||||
| Omit<SlashCommandIntegerOption, 'setAutocomplete'>
|
||||
| Omit<SlashCommandIntegerOption, 'addChoice' | 'addChoices'>
|
||||
| ((
|
||||
builder: SlashCommandIntegerOption,
|
||||
) =>
|
||||
| SlashCommandIntegerOption
|
||||
| Omit<SlashCommandIntegerOption, 'setAutocomplete'>
|
||||
| Omit<SlashCommandIntegerOption, 'addChoice' | 'addChoices'>),
|
||||
) {
|
||||
return this._sharedAddOptionMethod(input, SlashCommandIntegerOption);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a number option
|
||||
*
|
||||
* @param input A function that returns an option builder, or an already built builder
|
||||
*/
|
||||
public addNumberOption(
|
||||
input:
|
||||
| SlashCommandNumberOption
|
||||
| Omit<SlashCommandNumberOption, 'setAutocomplete'>
|
||||
| Omit<SlashCommandNumberOption, 'addChoice' | 'addChoices'>
|
||||
| ((
|
||||
builder: SlashCommandNumberOption,
|
||||
) =>
|
||||
| SlashCommandNumberOption
|
||||
| Omit<SlashCommandNumberOption, 'setAutocomplete'>
|
||||
| Omit<SlashCommandNumberOption, 'addChoice' | 'addChoices'>),
|
||||
) {
|
||||
return this._sharedAddOptionMethod(input, SlashCommandNumberOption);
|
||||
}
|
||||
|
||||
private _sharedAddOptionMethod<T extends ApplicationCommandOptionBase>(
|
||||
input:
|
||||
| T
|
||||
| Omit<T, 'setAutocomplete'>
|
||||
| Omit<T, 'addChoice' | 'addChoices'>
|
||||
| ((builder: T) => T | Omit<T, 'setAutocomplete'> | Omit<T, 'addChoice' | 'addChoices'>),
|
||||
Instance: new () => T,
|
||||
): ShouldOmitSubcommandFunctions extends true ? Omit<this, 'addSubcommand' | 'addSubcommandGroup'> : this {
|
||||
const { options } = this;
|
||||
|
||||
// First, assert options conditions - we cannot have more than 25 options
|
||||
validateMaxOptionsLength(options);
|
||||
|
||||
// Get the final result
|
||||
const result = typeof input === 'function' ? input(new Instance()) : input;
|
||||
|
||||
assertReturnOfBuilder(result, Instance);
|
||||
|
||||
// Push it
|
||||
options.push(result);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { APIApplicationCommandBooleanOption, ApplicationCommandOptionType } from 'discord-api-types/v9';
|
||||
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
|
||||
|
||||
export class SlashCommandBooleanOption extends ApplicationCommandOptionBase {
|
||||
public readonly type = ApplicationCommandOptionType.Boolean as const;
|
||||
|
||||
public toJSON(): APIApplicationCommandBooleanOption {
|
||||
this.runRequiredValidations();
|
||||
|
||||
return { ...this };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { APIApplicationCommandChannelOption, ApplicationCommandOptionType } from 'discord-api-types/v9';
|
||||
import { mix } from 'ts-mixer';
|
||||
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
|
||||
import { ApplicationCommandOptionChannelTypesMixin } from '../mixins/ApplicationCommandOptionChannelTypesMixin';
|
||||
|
||||
@mix(ApplicationCommandOptionChannelTypesMixin)
|
||||
export class SlashCommandChannelOption extends ApplicationCommandOptionBase {
|
||||
public override readonly type = ApplicationCommandOptionType.Channel as const;
|
||||
|
||||
public toJSON(): APIApplicationCommandChannelOption {
|
||||
this.runRequiredValidations();
|
||||
|
||||
return { ...this };
|
||||
}
|
||||
}
|
||||
|
||||
export interface SlashCommandChannelOption extends ApplicationCommandOptionChannelTypesMixin {}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { APIApplicationCommandIntegerOption, ApplicationCommandOptionType } from 'discord-api-types/v9';
|
||||
import { mix } from 'ts-mixer';
|
||||
import { z } from 'zod';
|
||||
import { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/ApplicationCommandNumericOptionMinMaxValueMixin';
|
||||
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
|
||||
import { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin';
|
||||
|
||||
const numberValidator = z.number().int().nonnegative();
|
||||
|
||||
@mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
|
||||
export class SlashCommandIntegerOption
|
||||
extends ApplicationCommandOptionBase
|
||||
implements ApplicationCommandNumericOptionMinMaxValueMixin
|
||||
{
|
||||
public readonly type = ApplicationCommandOptionType.Integer as const;
|
||||
|
||||
public setMaxValue(max: number): this {
|
||||
numberValidator.parse(max);
|
||||
|
||||
Reflect.set(this, 'max_value', max);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setMinValue(min: number): this {
|
||||
numberValidator.parse(min);
|
||||
|
||||
Reflect.set(this, 'min_value', min);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public toJSON(): APIApplicationCommandIntegerOption {
|
||||
this.runRequiredValidations();
|
||||
|
||||
if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {
|
||||
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
||||
}
|
||||
|
||||
return { ...this };
|
||||
}
|
||||
}
|
||||
|
||||
export interface SlashCommandIntegerOption
|
||||
extends ApplicationCommandNumericOptionMinMaxValueMixin,
|
||||
ApplicationCommandOptionWithChoicesAndAutocompleteMixin<number> {}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { APIApplicationCommandMentionableOption, ApplicationCommandOptionType } from 'discord-api-types/v9';
|
||||
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
|
||||
|
||||
export class SlashCommandMentionableOption extends ApplicationCommandOptionBase {
|
||||
public readonly type = ApplicationCommandOptionType.Mentionable as const;
|
||||
|
||||
public toJSON(): APIApplicationCommandMentionableOption {
|
||||
this.runRequiredValidations();
|
||||
|
||||
return { ...this };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { APIApplicationCommandNumberOption, ApplicationCommandOptionType } from 'discord-api-types/v9';
|
||||
import { mix } from 'ts-mixer';
|
||||
import { z } from 'zod';
|
||||
import { ApplicationCommandNumericOptionMinMaxValueMixin } from '../mixins/ApplicationCommandNumericOptionMinMaxValueMixin';
|
||||
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
|
||||
import { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin';
|
||||
|
||||
const numberValidator = z.number().nonnegative();
|
||||
|
||||
@mix(ApplicationCommandNumericOptionMinMaxValueMixin, ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
|
||||
export class SlashCommandNumberOption
|
||||
extends ApplicationCommandOptionBase
|
||||
implements ApplicationCommandNumericOptionMinMaxValueMixin
|
||||
{
|
||||
public readonly type = ApplicationCommandOptionType.Number as const;
|
||||
|
||||
public setMaxValue(max: number): this {
|
||||
numberValidator.parse(max);
|
||||
|
||||
Reflect.set(this, 'max_value', max);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public setMinValue(min: number): this {
|
||||
numberValidator.parse(min);
|
||||
|
||||
Reflect.set(this, 'min_value', min);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public toJSON(): APIApplicationCommandNumberOption {
|
||||
this.runRequiredValidations();
|
||||
|
||||
if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {
|
||||
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
||||
}
|
||||
|
||||
return { ...this };
|
||||
}
|
||||
}
|
||||
|
||||
export interface SlashCommandNumberOption
|
||||
extends ApplicationCommandNumericOptionMinMaxValueMixin,
|
||||
ApplicationCommandOptionWithChoicesAndAutocompleteMixin<number> {}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { APIApplicationCommandRoleOption, ApplicationCommandOptionType } from 'discord-api-types/v9';
|
||||
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
|
||||
|
||||
export class SlashCommandRoleOption extends ApplicationCommandOptionBase {
|
||||
public override readonly type = ApplicationCommandOptionType.Role as const;
|
||||
|
||||
public toJSON(): APIApplicationCommandRoleOption {
|
||||
this.runRequiredValidations();
|
||||
|
||||
return { ...this };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { APIApplicationCommandStringOption, ApplicationCommandOptionType } from 'discord-api-types/v9';
|
||||
import { mix } from 'ts-mixer';
|
||||
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
|
||||
import { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin';
|
||||
|
||||
@mix(ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
|
||||
export class SlashCommandStringOption extends ApplicationCommandOptionBase {
|
||||
public readonly type = ApplicationCommandOptionType.String as const;
|
||||
|
||||
public toJSON(): APIApplicationCommandStringOption {
|
||||
this.runRequiredValidations();
|
||||
|
||||
if (this.autocomplete && Array.isArray(this.choices) && this.choices.length > 0) {
|
||||
throw new RangeError('Autocomplete and choices are mutually exclusive to each other.');
|
||||
}
|
||||
|
||||
return { ...this };
|
||||
}
|
||||
}
|
||||
|
||||
export interface SlashCommandStringOption extends ApplicationCommandOptionWithChoicesAndAutocompleteMixin<string> {}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { APIApplicationCommandUserOption, ApplicationCommandOptionType } from 'discord-api-types/v9';
|
||||
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
|
||||
|
||||
export class SlashCommandUserOption extends ApplicationCommandOptionBase {
|
||||
public readonly type = ApplicationCommandOptionType.User as const;
|
||||
|
||||
public toJSON(): APIApplicationCommandUserOption {
|
||||
this.runRequiredValidations();
|
||||
|
||||
return { ...this };
|
||||
}
|
||||
}
|
||||
36
packages/builders/src/messages/embed/Assertions.ts
Normal file
36
packages/builders/src/messages/embed/Assertions.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { APIEmbedField } from 'discord-api-types/v9';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const fieldNamePredicate = z.string().min(1).max(256);
|
||||
|
||||
export const fieldValuePredicate = z.string().min(1).max(1024);
|
||||
|
||||
export const fieldInlinePredicate = z.boolean().optional();
|
||||
|
||||
export const embedFieldPredicate = z.object({
|
||||
name: fieldNamePredicate,
|
||||
value: fieldValuePredicate,
|
||||
inline: fieldInlinePredicate,
|
||||
});
|
||||
|
||||
export const embedFieldsArrayPredicate = embedFieldPredicate.array();
|
||||
|
||||
export const fieldLengthPredicate = z.number().lte(25);
|
||||
|
||||
export function validateFieldLength(fields: APIEmbedField[], amountAdding: number): void {
|
||||
fieldLengthPredicate.parse(fields.length + amountAdding);
|
||||
}
|
||||
|
||||
export const authorNamePredicate = fieldNamePredicate.nullable();
|
||||
|
||||
export const urlPredicate = z.string().url().nullish();
|
||||
|
||||
export const colorPredicate = z.number().gte(0).lte(0xffffff).nullable();
|
||||
|
||||
export const descriptionPredicate = z.string().min(1).max(4096).nullable();
|
||||
|
||||
export const footerTextPredicate = z.string().min(1).max(2048).nullable();
|
||||
|
||||
export const timestampPredicate = z.union([z.number(), z.date()]).nullable();
|
||||
|
||||
export const titlePredicate = fieldNamePredicate.nullable();
|
||||
326
packages/builders/src/messages/embed/Embed.ts
Normal file
326
packages/builders/src/messages/embed/Embed.ts
Normal file
@@ -0,0 +1,326 @@
|
||||
import type {
|
||||
APIEmbed,
|
||||
APIEmbedAuthor,
|
||||
APIEmbedField,
|
||||
APIEmbedFooter,
|
||||
APIEmbedImage,
|
||||
APIEmbedProvider,
|
||||
APIEmbedThumbnail,
|
||||
APIEmbedVideo,
|
||||
} from 'discord-api-types/v9';
|
||||
import {
|
||||
authorNamePredicate,
|
||||
colorPredicate,
|
||||
descriptionPredicate,
|
||||
embedFieldsArrayPredicate,
|
||||
fieldInlinePredicate,
|
||||
fieldNamePredicate,
|
||||
fieldValuePredicate,
|
||||
footerTextPredicate,
|
||||
timestampPredicate,
|
||||
titlePredicate,
|
||||
urlPredicate,
|
||||
validateFieldLength,
|
||||
} from './Assertions';
|
||||
|
||||
export interface AuthorOptions {
|
||||
name: string;
|
||||
url?: string;
|
||||
iconURL?: string;
|
||||
}
|
||||
|
||||
export interface FooterOptions {
|
||||
text: string;
|
||||
iconURL?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an embed in a message (image/video preview, rich embed, etc.)
|
||||
*/
|
||||
export class Embed implements APIEmbed {
|
||||
/**
|
||||
* An array of fields of this embed
|
||||
*/
|
||||
public fields: APIEmbedField[];
|
||||
|
||||
/**
|
||||
* The embed title
|
||||
*/
|
||||
public title?: string;
|
||||
|
||||
/**
|
||||
* The embed description
|
||||
*/
|
||||
public description?: string;
|
||||
|
||||
/**
|
||||
* The embed url
|
||||
*/
|
||||
public url?: string;
|
||||
|
||||
/**
|
||||
* The embed color
|
||||
*/
|
||||
public color?: number;
|
||||
|
||||
/**
|
||||
* The timestamp of the embed in the ISO format
|
||||
*/
|
||||
public timestamp?: string;
|
||||
|
||||
/**
|
||||
* The embed thumbnail data
|
||||
*/
|
||||
public thumbnail?: APIEmbedThumbnail;
|
||||
|
||||
/**
|
||||
* The embed image data
|
||||
*/
|
||||
public image?: APIEmbedImage;
|
||||
|
||||
/**
|
||||
* Received video data
|
||||
*/
|
||||
public video?: APIEmbedVideo;
|
||||
|
||||
/**
|
||||
* The embed author data
|
||||
*/
|
||||
public author?: APIEmbedAuthor;
|
||||
|
||||
/**
|
||||
* Received data about the embed provider
|
||||
*/
|
||||
public provider?: APIEmbedProvider;
|
||||
|
||||
/**
|
||||
* The embed footer data
|
||||
*/
|
||||
public footer?: APIEmbedFooter;
|
||||
|
||||
public constructor(data: APIEmbed = {}) {
|
||||
this.title = data.title;
|
||||
this.description = data.description;
|
||||
this.url = data.url;
|
||||
this.color = data.color;
|
||||
this.thumbnail = data.thumbnail;
|
||||
this.image = data.image;
|
||||
this.video = data.video;
|
||||
this.author = data.author;
|
||||
this.provider = data.provider;
|
||||
this.footer = data.footer;
|
||||
this.fields = data.fields ?? [];
|
||||
|
||||
if (data.timestamp) this.timestamp = new Date(data.timestamp).toISOString();
|
||||
}
|
||||
|
||||
/**
|
||||
* The accumulated length for the embed title, description, fields, footer text, and author name
|
||||
*/
|
||||
public get length(): number {
|
||||
return (
|
||||
(this.title?.length ?? 0) +
|
||||
(this.description?.length ?? 0) +
|
||||
this.fields.reduce((prev, curr) => prev + curr.name.length + curr.value.length, 0) +
|
||||
(this.footer?.text.length ?? 0) +
|
||||
(this.author?.name.length ?? 0)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a field to the embed (max 25)
|
||||
*
|
||||
* @param field The field to add.
|
||||
*/
|
||||
public addField(field: APIEmbedField): this {
|
||||
return this.addFields(field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds fields to the embed (max 25)
|
||||
*
|
||||
* @param fields The fields to add
|
||||
*/
|
||||
public addFields(...fields: APIEmbedField[]): this {
|
||||
// Data assertions
|
||||
embedFieldsArrayPredicate.parse(fields);
|
||||
|
||||
// Ensure adding these fields won't exceed the 25 field limit
|
||||
validateFieldLength(this.fields, fields.length);
|
||||
|
||||
this.fields.push(...Embed.normalizeFields(...fields));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes, replaces, or inserts fields in the embed (max 25)
|
||||
*
|
||||
* @param index The index to start at
|
||||
* @param deleteCount The number of fields to remove
|
||||
* @param fields The replacing field objects
|
||||
*/
|
||||
public spliceFields(index: number, deleteCount: number, ...fields: APIEmbedField[]): this {
|
||||
// Data assertions
|
||||
embedFieldsArrayPredicate.parse(fields);
|
||||
|
||||
// Ensure adding these fields won't exceed the 25 field limit
|
||||
validateFieldLength(this.fields, fields.length - deleteCount);
|
||||
|
||||
this.fields.splice(index, deleteCount, ...Embed.normalizeFields(...fields));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the author of this embed
|
||||
*
|
||||
* @param options The options for the author
|
||||
*/
|
||||
public setAuthor(options: AuthorOptions | null): this {
|
||||
if (options === null) {
|
||||
this.author = undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
const { name, iconURL, url } = options;
|
||||
// Data assertions
|
||||
authorNamePredicate.parse(name);
|
||||
urlPredicate.parse(iconURL);
|
||||
urlPredicate.parse(url);
|
||||
|
||||
this.author = { name, url, icon_url: iconURL };
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color of this embed
|
||||
*
|
||||
* @param color The color of the embed
|
||||
*/
|
||||
public setColor(color: number | null): this {
|
||||
// Data assertions
|
||||
colorPredicate.parse(color);
|
||||
|
||||
this.color = color ?? undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the description of this embed
|
||||
*
|
||||
* @param description The description
|
||||
*/
|
||||
public setDescription(description: string | null): this {
|
||||
// Data assertions
|
||||
descriptionPredicate.parse(description);
|
||||
|
||||
this.description = description ?? undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the footer of this embed
|
||||
*
|
||||
* @param options The options for the footer
|
||||
*/
|
||||
public setFooter(options: FooterOptions | null): this {
|
||||
if (options === null) {
|
||||
this.footer = undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
const { text, iconURL } = options;
|
||||
// Data assertions
|
||||
footerTextPredicate.parse(text);
|
||||
urlPredicate.parse(iconURL);
|
||||
|
||||
this.footer = { text, icon_url: iconURL };
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the image of this embed
|
||||
*
|
||||
* @param url The URL of the image
|
||||
*/
|
||||
public setImage(url: string | null): this {
|
||||
// Data assertions
|
||||
urlPredicate.parse(url);
|
||||
|
||||
this.image = url ? { url } : undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the thumbnail of this embed
|
||||
*
|
||||
* @param url The URL of the thumbnail
|
||||
*/
|
||||
public setThumbnail(url: string | null): this {
|
||||
// Data assertions
|
||||
urlPredicate.parse(url);
|
||||
|
||||
this.thumbnail = url ? { url } : undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timestamp of this embed
|
||||
*
|
||||
* @param timestamp The timestamp or date
|
||||
*/
|
||||
public setTimestamp(timestamp: number | Date | null = Date.now()): this {
|
||||
// Data assertions
|
||||
timestampPredicate.parse(timestamp);
|
||||
|
||||
this.timestamp = timestamp ? new Date(timestamp).toISOString() : undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the title of this embed
|
||||
*
|
||||
* @param title The title
|
||||
*/
|
||||
public setTitle(title: string | null): this {
|
||||
// Data assertions
|
||||
titlePredicate.parse(title);
|
||||
|
||||
this.title = title ?? undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URL of this embed
|
||||
*
|
||||
* @param url The URL
|
||||
*/
|
||||
public setURL(url: string | null): this {
|
||||
// Data assertions
|
||||
urlPredicate.parse(url);
|
||||
|
||||
this.url = url ?? undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the embed to a plain object
|
||||
*/
|
||||
public toJSON(): APIEmbed {
|
||||
return { ...this };
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes field input and resolves strings
|
||||
*
|
||||
* @param fields Fields to normalize
|
||||
*/
|
||||
public static normalizeFields(...fields: APIEmbedField[]): APIEmbedField[] {
|
||||
return fields.flat(Infinity).map((field) => {
|
||||
fieldNamePredicate.parse(field.name);
|
||||
fieldValuePredicate.parse(field.value);
|
||||
fieldInlinePredicate.parse(field.inline);
|
||||
|
||||
return { name: field.name, value: field.value, inline: field.inline ?? undefined };
|
||||
});
|
||||
}
|
||||
}
|
||||
319
packages/builders/src/messages/formatters.ts
Normal file
319
packages/builders/src/messages/formatters.ts
Normal file
@@ -0,0 +1,319 @@
|
||||
import type { Snowflake } from 'discord-api-types/globals';
|
||||
import type { URL } from 'url';
|
||||
|
||||
/**
|
||||
* Wraps the content inside a codeblock with no language
|
||||
*
|
||||
* @param content The content to wrap
|
||||
*/
|
||||
export function codeBlock<C extends string>(content: C): `\`\`\`\n${C}\`\`\``;
|
||||
|
||||
/**
|
||||
* Wraps the content inside a codeblock with the specified language
|
||||
*
|
||||
* @param language The language for the codeblock
|
||||
* @param content The content to wrap
|
||||
*/
|
||||
export function codeBlock<L extends string, C extends string>(language: L, content: C): `\`\`\`${L}\n${C}\`\`\``;
|
||||
export function codeBlock(language: string, content?: string): string {
|
||||
return typeof content === 'undefined' ? `\`\`\`\n${language}\`\`\`` : `\`\`\`${language}\n${content}\`\`\``;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the content inside \`backticks\`, which formats it as inline code
|
||||
*
|
||||
* @param content The content to wrap
|
||||
*/
|
||||
export function inlineCode<C extends string>(content: C): `\`${C}\`` {
|
||||
return `\`${content}\``;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the content into italic text
|
||||
*
|
||||
* @param content The content to wrap
|
||||
*/
|
||||
export function italic<C extends string>(content: C): `_${C}_` {
|
||||
return `_${content}_`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the content into bold text
|
||||
*
|
||||
* @param content The content to wrap
|
||||
*/
|
||||
export function bold<C extends string>(content: C): `**${C}**` {
|
||||
return `**${content}**`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the content into underscored text
|
||||
*
|
||||
* @param content The content to wrap
|
||||
*/
|
||||
export function underscore<C extends string>(content: C): `__${C}__` {
|
||||
return `__${content}__`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the content into strike-through text
|
||||
*
|
||||
* @param content The content to wrap
|
||||
*/
|
||||
export function strikethrough<C extends string>(content: C): `~~${C}~~` {
|
||||
return `~~${content}~~`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the content into a quote. This needs to be at the start of the line for Discord to format it
|
||||
*
|
||||
* @param content The content to wrap
|
||||
*/
|
||||
export function quote<C extends string>(content: C): `> ${C}` {
|
||||
return `> ${content}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the content into a block quote. This needs to be at the start of the line for Discord to format it
|
||||
*
|
||||
* @param content The content to wrap
|
||||
*/
|
||||
export function blockQuote<C extends string>(content: C): `>>> ${C}` {
|
||||
return `>>> ${content}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the URL into `<>`, which stops it from embedding
|
||||
*
|
||||
* @param url The URL to wrap
|
||||
*/
|
||||
export function hideLinkEmbed<C extends string>(url: C): `<${C}>`;
|
||||
|
||||
/**
|
||||
* Wraps the URL into `<>`, which stops it from embedding
|
||||
*
|
||||
* @param url The URL to wrap
|
||||
*/
|
||||
export function hideLinkEmbed(url: URL): `<${string}>`;
|
||||
export function hideLinkEmbed(url: string | URL) {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
return `<${url}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the content and the URL into a masked URL
|
||||
*
|
||||
* @param content The content to display
|
||||
* @param url The URL the content links to
|
||||
*/
|
||||
export function hyperlink<C extends string>(content: C, url: URL): `[${C}](${string})`;
|
||||
|
||||
/**
|
||||
* Formats the content and the URL into a masked URL
|
||||
*
|
||||
* @param content The content to display
|
||||
* @param url The URL the content links to
|
||||
*/
|
||||
export function hyperlink<C extends string, U extends string>(content: C, url: U): `[${C}](${U})`;
|
||||
|
||||
/**
|
||||
* Formats the content and the URL into a masked URL
|
||||
*
|
||||
* @param content The content to display
|
||||
* @param url The URL the content links to
|
||||
* @param title The title shown when hovering on the masked link
|
||||
*/
|
||||
export function hyperlink<C extends string, T extends string>(
|
||||
content: C,
|
||||
url: URL,
|
||||
title: T,
|
||||
): `[${C}](${string} "${T}")`;
|
||||
|
||||
/**
|
||||
* Formats the content and the URL into a masked URL
|
||||
*
|
||||
* @param content The content to display
|
||||
* @param url The URL the content links to
|
||||
* @param title The title shown when hovering on the masked link
|
||||
*/
|
||||
export function hyperlink<C extends string, U extends string, T extends string>(
|
||||
content: C,
|
||||
url: U,
|
||||
title: T,
|
||||
): `[${C}](${U} "${T}")`;
|
||||
export function hyperlink(content: string, url: string | URL, title?: string) {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
return title ? `[${content}](${url} "${title}")` : `[${content}](${url})`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the content inside spoiler (hidden text)
|
||||
*
|
||||
* @param content The content to wrap
|
||||
*/
|
||||
export function spoiler<C extends string>(content: C): `||${C}||` {
|
||||
return `||${content}||`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a user ID into a user mention
|
||||
*
|
||||
* @param userId The user ID to format
|
||||
*/
|
||||
export function userMention<C extends Snowflake>(userId: C): `<@${C}>` {
|
||||
return `<@${userId}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a user ID into a member-nickname mention
|
||||
*
|
||||
* @param memberId The user ID to format
|
||||
*/
|
||||
export function memberNicknameMention<C extends Snowflake>(memberId: C): `<@!${C}>` {
|
||||
return `<@!${memberId}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a channel ID into a channel mention
|
||||
*
|
||||
* @param channelId The channel ID to format
|
||||
*/
|
||||
export function channelMention<C extends Snowflake>(channelId: C): `<#${C}>` {
|
||||
return `<#${channelId}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a role ID into a role mention
|
||||
*
|
||||
* @param roleId The role ID to format
|
||||
*/
|
||||
export function roleMention<C extends Snowflake>(roleId: C): `<@&${C}>` {
|
||||
return `<@&${roleId}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an emoji ID into a fully qualified emoji identifier
|
||||
*
|
||||
* @param emojiId The emoji ID to format
|
||||
*/
|
||||
export function formatEmoji<C extends Snowflake>(emojiId: C, animated?: false): `<:_:${C}>`;
|
||||
|
||||
/**
|
||||
* Formats an emoji ID into a fully qualified emoji identifier
|
||||
*
|
||||
* @param emojiId The emoji ID to format
|
||||
* @param animated Whether the emoji is animated or not. Defaults to `false`
|
||||
*/
|
||||
export function formatEmoji<C extends Snowflake>(emojiId: C, animated?: true): `<a:_:${C}>`;
|
||||
|
||||
/**
|
||||
* Formats an emoji ID into a fully qualified emoji identifier
|
||||
*
|
||||
* @param emojiId The emoji ID to format
|
||||
* @param animated Whether the emoji is animated or not. Defaults to `false`
|
||||
*/
|
||||
export function formatEmoji<C extends Snowflake>(emojiId: C, animated = false): `<a:_:${C}>` | `<:_:${C}>` {
|
||||
return `<${animated ? 'a' : ''}:_:${emojiId}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a date into a short date-time string
|
||||
*
|
||||
* @param date The date to format, defaults to the current time
|
||||
*/
|
||||
export function time(date?: Date): `<t:${bigint}>`;
|
||||
|
||||
/**
|
||||
* Formats a date given a format style
|
||||
*
|
||||
* @param date The date to format
|
||||
* @param style The style to use
|
||||
*/
|
||||
export function time<S extends TimestampStylesString>(date: Date, style: S): `<t:${bigint}:${S}>`;
|
||||
|
||||
/**
|
||||
* Formats the given timestamp into a short date-time string
|
||||
*
|
||||
* @param seconds The time to format, represents an UNIX timestamp in seconds
|
||||
*/
|
||||
export function time<C extends number>(seconds: C): `<t:${C}>`;
|
||||
|
||||
/**
|
||||
* Formats the given timestamp into a short date-time string
|
||||
*
|
||||
* @param seconds The time to format, represents an UNIX timestamp in seconds
|
||||
* @param style The style to use
|
||||
*/
|
||||
export function time<C extends number, S extends TimestampStylesString>(seconds: C, style: S): `<t:${C}:${S}>`;
|
||||
export function time(timeOrSeconds?: number | Date, style?: TimestampStylesString): string {
|
||||
if (typeof timeOrSeconds !== 'number') {
|
||||
timeOrSeconds = Math.floor((timeOrSeconds?.getTime() ?? Date.now()) / 1000);
|
||||
}
|
||||
|
||||
return typeof style === 'string' ? `<t:${timeOrSeconds}:${style}>` : `<t:${timeOrSeconds}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The [message formatting timestamp styles](https://discord.com/developers/docs/reference#message-formatting-timestamp-styles) supported by Discord
|
||||
*/
|
||||
export const TimestampStyles = {
|
||||
/**
|
||||
* Short time format, consisting of hours and minutes, e.g. 16:20
|
||||
*/
|
||||
ShortTime: 't',
|
||||
|
||||
/**
|
||||
* Long time format, consisting of hours, minutes, and seconds, e.g. 16:20:30
|
||||
*/
|
||||
LongTime: 'T',
|
||||
|
||||
/**
|
||||
* Short date format, consisting of day, month, and year, e.g. 20/04/2021
|
||||
*/
|
||||
ShortDate: 'd',
|
||||
|
||||
/**
|
||||
* Long date format, consisting of day, month, and year, e.g. 20 April 2021
|
||||
*/
|
||||
LongDate: 'D',
|
||||
|
||||
/**
|
||||
* Short date-time format, consisting of short date and short time formats, e.g. 20 April 2021 16:20
|
||||
*/
|
||||
ShortDateTime: 'f',
|
||||
|
||||
/**
|
||||
* Long date-time format, consisting of long date and short time formats, e.g. Tuesday, 20 April 2021 16:20
|
||||
*/
|
||||
LongDateTime: 'F',
|
||||
|
||||
/**
|
||||
* Relative time format, consisting of a relative duration format, e.g. 2 months ago
|
||||
*/
|
||||
RelativeTime: 'R',
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* The possible values, see {@link TimestampStyles} for more information
|
||||
*/
|
||||
export type TimestampStylesString = typeof TimestampStyles[keyof typeof TimestampStyles];
|
||||
|
||||
/**
|
||||
* An enum with all the available faces from Discord's native slash commands
|
||||
*/
|
||||
export enum Faces {
|
||||
/**
|
||||
* ¯\\_(ツ)\\_/¯
|
||||
*/
|
||||
Shrug = '¯\\_(ツ)\\_/¯',
|
||||
|
||||
/**
|
||||
* (╯°□°)╯︵ ┻━┻
|
||||
*/
|
||||
Tableflip = '(╯°□°)╯︵ ┻━┻',
|
||||
|
||||
/**
|
||||
* ┬─┬ ノ( ゜-゜ノ)
|
||||
*/
|
||||
Unflip = '┬─┬ ノ( ゜-゜ノ)',
|
||||
}
|
||||
20
packages/builders/tsconfig.eslint.json
Normal file
20
packages/builders/tsconfig.eslint.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
"**/*.js",
|
||||
"**/*.mjs",
|
||||
"**/*.jsx",
|
||||
"**/*.test.ts",
|
||||
"**/*.test.js",
|
||||
"**/*.test.mjs",
|
||||
"**/*.spec.ts",
|
||||
"**/*.spec.js",
|
||||
"**/*.spec.mjs"
|
||||
],
|
||||
"exclude": []
|
||||
}
|
||||
4
packages/builders/tsconfig.json
Normal file
4
packages/builders/tsconfig.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
12
packages/builders/tsup.config.ts
Normal file
12
packages/builders/tsup.config.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { Options } from 'tsup';
|
||||
|
||||
export const tsup: Options = {
|
||||
clean: true,
|
||||
dts: true,
|
||||
entryPoints: ['src/index.ts'],
|
||||
format: ['esm', 'cjs'],
|
||||
minify: true,
|
||||
skipNodeModulesBundle: true,
|
||||
sourcemap: true,
|
||||
target: 'es2021',
|
||||
};
|
||||
16
packages/collection/.eslintrc.json
Normal file
16
packages/collection/.eslintrc.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"root": true,
|
||||
"extends": "marine/prettier/node",
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.eslint.json",
|
||||
"extraFileExtensions": [".mjs"]
|
||||
},
|
||||
"ignorePatterns": ["**/dist/*"],
|
||||
"env": {
|
||||
"jest": true
|
||||
},
|
||||
"rules": {
|
||||
"no-redeclare": 0,
|
||||
"@typescript-eslint/naming-convention": 0
|
||||
}
|
||||
}
|
||||
27
packages/collection/.gitignore
vendored
Normal file
27
packages/collection/.gitignore
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
# Packages
|
||||
node_modules/
|
||||
|
||||
# Log files
|
||||
logs/
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Env
|
||||
.env
|
||||
|
||||
# Dist
|
||||
dist/
|
||||
typings/
|
||||
docs/**/*
|
||||
!docs/index.yml
|
||||
!docs/README.md
|
||||
|
||||
# Miscellaneous
|
||||
.tmp/
|
||||
coverage/
|
||||
tsconfig.tsbuildinfo
|
||||
8
packages/collection/.prettierrc.json
Normal file
8
packages/collection/.prettierrc.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"quoteProps": "as-needed",
|
||||
"trailingComma": "all",
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
3
packages/collection/.versionrc
Normal file
3
packages/collection/.versionrc
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"releaseCommitMessageFormat": "chore(Release): publish"
|
||||
}
|
||||
63
packages/collection/CHANGELOG.md
Normal file
63
packages/collection/CHANGELOG.md
Normal file
@@ -0,0 +1,63 @@
|
||||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
|
||||
# [0.4.0](https://github.com/discordjs/collection/compare/v0.3.2...v0.4.0) (2021-12-24)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add #reverse ([#48](https://github.com/discordjs/collection/issues/48)) ([8bcb5e2](https://github.com/discordjs/collection/commit/8bcb5e21bcc15f5b77612d8ff03dec6c37f4d449))
|
||||
* add Collection#ensure ([#52](https://github.com/discordjs/collection/issues/52)) ([3809eb4](https://github.com/discordjs/collection/commit/3809eb4d18e70459355d310919a3f57747eee3dd))
|
||||
|
||||
|
||||
|
||||
## [0.3.2](https://github.com/discordjs/collection/compare/v0.3.1...v0.3.2) (2021-10-29)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* update doc engine ([4c0e24f](https://github.com/discordjs/collection/commit/4c0e24fae0323db9de1991db9cfacc093d529abc))
|
||||
|
||||
|
||||
|
||||
## [0.3.1](https://github.com/discordjs/collection/compare/v0.3.0...v0.3.1) (2021-10-29)
|
||||
|
||||
|
||||
|
||||
# [0.3.0](https://github.com/discordjs/collection/compare/v0.2.4...v0.3.0) (2021-10-29)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add Collection#at() and Collection#keyAt() ([#46](https://github.com/discordjs/collection/issues/46)) ([66b30b9](https://github.com/discordjs/collection/commit/66b30b91069502493383c059cc38e27c152bf541))
|
||||
* improve documentation and resolve [#49](https://github.com/discordjs/collection/issues/49) ([aec01c6](https://github.com/discordjs/collection/commit/aec01c6ae3ff50b0b5f7c070bff10f01bf98d803))
|
||||
* ts-docgen ([463b131](https://github.com/discordjs/collection/commit/463b1314e60f2debc526454a6ccd7ce8a9a4ae8a))
|
||||
|
||||
|
||||
|
||||
## [0.2.4](https://github.com/discordjs/collection/compare/v0.2.3...v0.2.4) (2021-10-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* minification of names ([bd2fe2a](https://github.com/discordjs/collection/commit/bd2fe2a47c38f634b0334fe6e89f30f6f6a0b1f5))
|
||||
|
||||
|
||||
|
||||
## [0.2.3](https://github.com/discordjs/collection/compare/v0.2.2...v0.2.3) (2021-10-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* building with useDefineForClassFields false ([2a571d5](https://github.com/discordjs/collection/commit/2a571d5a2c90ed8b708c3c5c017e2f225cd494e9))
|
||||
|
||||
|
||||
|
||||
## [0.2.2](https://github.com/discordjs/collection/compare/v0.2.1...v0.2.2) (2021-10-27)
|
||||
|
||||
|
||||
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user