Compare commits
381 Commits
@discordjs
...
@discordjs
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7bc2d0db8 | ||
|
|
baeeb38185 | ||
|
|
1a0da18b36 | ||
|
|
ca7719e822 | ||
|
|
ec5d921b75 | ||
|
|
b42e499410 | ||
|
|
374a6785ae | ||
|
|
319a73f8e6 | ||
|
|
16d70b9232 | ||
|
|
4476fadd19 | ||
|
|
61251cfcb8 | ||
|
|
e77793898a | ||
|
|
f5b3f842e3 | ||
|
|
e32f0c141a | ||
|
|
fdac8c5bdd | ||
|
|
0d64ea0528 | ||
|
|
cce8194b9f | ||
|
|
f4b4918200 | ||
|
|
d500d97666 | ||
|
|
6727634758 | ||
|
|
a3c6bce3a8 | ||
|
|
214c6cbdd6 | ||
|
|
492039c4f6 | ||
|
|
b0542f30e2 | ||
|
|
84197a0ee0 | ||
|
|
33bfdedf35 | ||
|
|
caa7833ffb | ||
|
|
b14d8d970b | ||
|
|
d4d326b70d | ||
|
|
d4b0f4de5f | ||
|
|
f040c6f6a5 | ||
|
|
6f05c96ab4 | ||
|
|
62f2ca5fbb | ||
|
|
610b4bbacb | ||
|
|
8469fb3bad | ||
|
|
d25ef434ae | ||
|
|
2deea25e97 | ||
|
|
5c5b545c38 | ||
|
|
eeeef2ac50 | ||
|
|
ccbe0716a4 | ||
|
|
a9fcfc0586 | ||
|
|
36d6f0e55b | ||
|
|
1e060e5bde | ||
|
|
c5b71a756b | ||
|
|
6c781ede30 | ||
|
|
be38128ea1 | ||
|
|
737a97d068 | ||
|
|
b26af3cf38 | ||
|
|
169b05f319 | ||
|
|
bf0430f998 | ||
|
|
2da2fa01b2 | ||
|
|
1c5701651a | ||
|
|
b6a8264d6b | ||
|
|
a7196dc969 | ||
|
|
a03661844f | ||
|
|
fb2b7281e0 | ||
|
|
c303bf3329 | ||
|
|
c2c8cce1d7 | ||
|
|
abb84ce88f | ||
|
|
d317ca1053 | ||
|
|
072fbb228a | ||
|
|
548c25488a | ||
|
|
16a44f83e5 | ||
|
|
0dda270ea5 | ||
|
|
ee988e3e75 | ||
|
|
104ad754f3 | ||
|
|
0ff239a602 | ||
|
|
89fd19e08a | ||
|
|
6a6c7d0333 | ||
|
|
083f6abb38 | ||
|
|
5cc13b735c | ||
|
|
1e4d1dc04f | ||
|
|
177d81f596 | ||
|
|
bf4cfeb4bf | ||
|
|
11b236ff65 | ||
|
|
1d5b9837de | ||
|
|
8065b80cea | ||
|
|
3b26680672 | ||
|
|
c4dbd7ee9f | ||
|
|
72771b79aa | ||
|
|
63dbe48055 | ||
|
|
67c8953a10 | ||
|
|
30e35d909e | ||
|
|
6a5707c786 | ||
|
|
9b821e5dfc | ||
|
|
a04172325a | ||
|
|
154c00ded9 | ||
|
|
3b927449ae | ||
|
|
fcce0d95bb | ||
|
|
93e0f4cd10 | ||
|
|
abaae4ff16 | ||
|
|
270d9f1047 | ||
|
|
9ae737708b | ||
|
|
e382d60421 | ||
|
|
68aa202cd6 | ||
|
|
d8ad181c19 | ||
|
|
0dff969e16 | ||
|
|
79d999e4c1 | ||
|
|
215f8dc5e0 | ||
|
|
b6089e585e | ||
|
|
fe025c0a9f | ||
|
|
4a8aeb6aee | ||
|
|
3dd57c2eaf | ||
|
|
740da4ce5e | ||
|
|
6fb0b1cef6 | ||
|
|
ac6ff15b7d | ||
|
|
a294b47db0 | ||
|
|
ecef7bdf22 | ||
|
|
40578393c3 | ||
|
|
86ecb37c9e | ||
|
|
311e826b12 | ||
|
|
dceac0089d | ||
|
|
a2f7d3ad54 | ||
|
|
b532df61ed | ||
|
|
d60e0bf30b | ||
|
|
baa08b8fbb | ||
|
|
f469f74aca | ||
|
|
90d3b28268 | ||
|
|
a271e9b51e | ||
|
|
8ac0e1e5d6 | ||
|
|
9d6fdf8979 | ||
|
|
cafe58b3bd | ||
|
|
7eca844f6d | ||
|
|
63f5261f4c | ||
|
|
5be774db64 | ||
|
|
b36b751bde | ||
|
|
500712d5ea | ||
|
|
040c66ae15 | ||
|
|
82378fc2e8 | ||
|
|
d4f742e99e | ||
|
|
51ceb203fa | ||
|
|
1404e32849 | ||
|
|
9fc3e5ea72 | ||
|
|
19e74b1533 | ||
|
|
de22a10038 | ||
|
|
8ab30cdefa | ||
|
|
c2a43b685e | ||
|
|
507b696792 | ||
|
|
15f7571243 | ||
|
|
3fa429c7df | ||
|
|
7713627fd1 | ||
|
|
6a5c0fb32d | ||
|
|
eb5acd1e30 | ||
|
|
127021d5ab | ||
|
|
0943bc2efb | ||
|
|
a1c83c17d6 | ||
|
|
c0eae344c2 | ||
|
|
f2f757ce52 | ||
|
|
65cfa3ffd3 | ||
|
|
ee2eb7349f | ||
|
|
2d19163d76 | ||
|
|
9bca4af5fd | ||
|
|
fe5e344adc | ||
|
|
c8f6066d6a | ||
|
|
7e21a9474e | ||
|
|
d0a535ea6a | ||
|
|
8124fc68be | ||
|
|
dbd5354056 | ||
|
|
2ebb5cbd53 | ||
|
|
096cd92b87 | ||
|
|
37ef57b880 | ||
|
|
e3c247e423 | ||
|
|
5f3fc170fb | ||
|
|
20fade2a87 | ||
|
|
e827644b5a | ||
|
|
62815928ab | ||
|
|
7fb6630c02 | ||
|
|
737b80b5f2 | ||
|
|
481ccd228b | ||
|
|
a3fff7b8be | ||
|
|
8cdbe23766 | ||
|
|
d920933dc5 | ||
|
|
2d817df3b5 | ||
|
|
1605a2c289 | ||
|
|
464ea2ab30 | ||
|
|
0d1d54a537 | ||
|
|
dd8bb397a8 | ||
|
|
61d3d6d4ae | ||
|
|
512b0c67b9 | ||
|
|
532c3842bc | ||
|
|
edace17a13 | ||
|
|
d3154cf8f1 | ||
|
|
45552faf02 | ||
|
|
ebfd52695e | ||
|
|
595bded8a5 | ||
|
|
c74c632cdb | ||
|
|
fc003050de | ||
|
|
8702978057 | ||
|
|
c2b18d6d8b | ||
|
|
519aa3abe8 | ||
|
|
89c076c89e | ||
|
|
f224a07381 | ||
|
|
8e1e1be0c2 | ||
|
|
193a5e9e20 | ||
|
|
73c6bc2c36 | ||
|
|
b7f1ebc334 | ||
|
|
92aea94411 | ||
|
|
41dee5177d | ||
|
|
bbde371324 | ||
|
|
66b971899a | ||
|
|
43235d43fe | ||
|
|
31df3d21cd | ||
|
|
2663d76709 | ||
|
|
44a1e85847 | ||
|
|
d2e1924fa6 | ||
|
|
68dd260dee | ||
|
|
5e66f85f55 | ||
|
|
46060419a9 | ||
|
|
7c1b73cc69 | ||
|
|
95db597fc8 | ||
|
|
0047a49b73 | ||
|
|
32dff01f29 | ||
|
|
efa50fc3fa | ||
|
|
aa61c20ffd | ||
|
|
d48136bee1 | ||
|
|
46bf8f0146 | ||
|
|
7280d4e82e | ||
|
|
bd2914cc98 | ||
|
|
77804cfd55 | ||
|
|
8fea3ed978 | ||
|
|
05c63cd9a1 | ||
|
|
8d69b24b5c | ||
|
|
9baee4b2ce | ||
|
|
c986a99104 | ||
|
|
2b9e4cf9d0 | ||
|
|
1af2f4ed0e | ||
|
|
3fbfe9f1ae | ||
|
|
b901ff7c4c | ||
|
|
5f8915f6d1 | ||
|
|
ff42d7af72 | ||
|
|
0fdbabea98 | ||
|
|
e9944b3d2d | ||
|
|
2b9833cd36 | ||
|
|
7b2a2e3a15 | ||
|
|
6087088579 | ||
|
|
622acbcbf0 | ||
|
|
b2754d4a0e | ||
|
|
53cbb0e36d | ||
|
|
7ce6f2fc8a | ||
|
|
76042f0538 | ||
|
|
dedaa5d657 | ||
|
|
ed00a10e1f | ||
|
|
ae1deac2bf | ||
|
|
a367e2c8c9 | ||
|
|
7678f1176a | ||
|
|
4cca33d9b0 | ||
|
|
388783d7dd | ||
|
|
bda31284bf | ||
|
|
76968b4bc1 | ||
|
|
34343c6afa | ||
|
|
56c9396b71 | ||
|
|
21c283f964 | ||
|
|
13471fa1b7 | ||
|
|
b1ded63e42 | ||
|
|
565fc0192a | ||
|
|
33533b7284 | ||
|
|
be38f57926 | ||
|
|
f79ba52c7a | ||
|
|
72e0c99454 | ||
|
|
3d06c9d872 | ||
|
|
831aafa733 | ||
|
|
5faf074c14 | ||
|
|
297e959f48 | ||
|
|
1fc87a9698 | ||
|
|
366f7174d0 | ||
|
|
97c3237a70 | ||
|
|
c12217829b | ||
|
|
0873f9a4c3 | ||
|
|
6c77fee41b | ||
|
|
cda8d88ad5 | ||
|
|
665bf1486a | ||
|
|
99136d6be8 | ||
|
|
896dc8b21e | ||
|
|
651f2d036a | ||
|
|
2adee06b6e | ||
|
|
495bc60345 | ||
|
|
d9d578391a | ||
|
|
3c74aa2049 | ||
|
|
799fa54fa4 | ||
|
|
8a74f144ac | ||
|
|
dea68400a3 | ||
|
|
c13f18e90e | ||
|
|
aff772c7aa | ||
|
|
4594896b54 | ||
|
|
a11ff75631 | ||
|
|
9257a09abb | ||
|
|
4810f7c863 | ||
|
|
18ce10a9af | ||
|
|
ed1c1737df | ||
|
|
90ed51e06e | ||
|
|
641a980b60 | ||
|
|
1f2047ff90 | ||
|
|
23636a9a2f | ||
|
|
6a6bc63973 | ||
|
|
b715b7d653 | ||
|
|
2cb2d81b82 | ||
|
|
0411ce268e | ||
|
|
584bd6f2fc | ||
|
|
c887388db6 | ||
|
|
4059432c78 | ||
|
|
6b34486f3f | ||
|
|
b3f3d54f18 | ||
|
|
ea597aa886 | ||
|
|
5e08ea68d2 | ||
|
|
ec7b20f51d | ||
|
|
74df5c7fa4 | ||
|
|
cec816f9f5 | ||
|
|
3979f0b6e6 | ||
|
|
13dc779029 | ||
|
|
fc0b6f7f8e | ||
|
|
a5afc406b9 | ||
|
|
437437461e | ||
|
|
e2e71b4d09 | ||
|
|
bddf018f26 | ||
|
|
ec9080b883 | ||
|
|
bba0e72e22 | ||
|
|
00accf7470 | ||
|
|
dd795da790 | ||
|
|
b0f8df0f6c | ||
|
|
bf83db9480 | ||
|
|
1b1ae2f0cb | ||
|
|
1f7d1f8094 | ||
|
|
9907ff915e | ||
|
|
9b707f2b83 | ||
|
|
5d92525596 | ||
|
|
45f7e1a2e8 | ||
|
|
69adc6f4b9 | ||
|
|
3d37660107 | ||
|
|
87776bb0e8 | ||
|
|
2d5531f35c | ||
|
|
bbef68d271 | ||
|
|
c63bde9479 | ||
|
|
2ca187bd34 | ||
|
|
8fb400827f | ||
|
|
bb71dc825e | ||
|
|
defb083528 | ||
|
|
a6de2707fc | ||
|
|
432e9b8425 | ||
|
|
54303d085d | ||
|
|
5c90b7f716 | ||
|
|
f623e7a315 | ||
|
|
bb459d95e9 | ||
|
|
48682ad474 | ||
|
|
057fc89c92 | ||
|
|
dc13324ddc | ||
|
|
de94eaf351 | ||
|
|
8f97d2bacf | ||
|
|
5eabec14d4 | ||
|
|
785ec8fd75 | ||
|
|
6b383350a6 | ||
|
|
bf6761a44a | ||
|
|
fcd35ea2e7 | ||
|
|
b2970bb2dd | ||
|
|
efa16a6095 | ||
|
|
be04acd534 | ||
|
|
9461045e5a | ||
|
|
3654efede2 | ||
|
|
d8e94d8f10 | ||
|
|
4f59b740d0 | ||
|
|
093ac924ae | ||
|
|
ab8bf0f4d2 | ||
|
|
9c76bbea17 | ||
|
|
b8397b24e5 | ||
|
|
ba0cb66ff9 | ||
|
|
15021990e8 | ||
|
|
a76b1b60f7 | ||
|
|
9c8784fe51 | ||
|
|
b0e57126dc | ||
|
|
e723230dff | ||
|
|
38c699bc8a | ||
|
|
c5d40d3807 | ||
|
|
02d196474a | ||
|
|
68031210f5 | ||
|
|
3cdddbe31d | ||
|
|
757bed0b1f | ||
|
|
599ad3eab5 | ||
|
|
7f60a8fc5d | ||
|
|
885defbce4 | ||
|
|
4f174c644d | ||
|
|
346d1be72b | ||
|
|
94cc02a258 |
@@ -5,8 +5,9 @@
|
||||
"type-enum": [
|
||||
2,
|
||||
"always",
|
||||
["chore", "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test", "types", "typings"]
|
||||
["chore", "build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test", "types"]
|
||||
],
|
||||
"scope-case": [0]
|
||||
"scope-case": [0],
|
||||
"subject-exclamation-mark": [0]
|
||||
}
|
||||
}
|
||||
|
||||
6
.github/CODEOWNERS
vendored
@@ -1,12 +1,8 @@
|
||||
# Learn how to add code owners here:
|
||||
# https://help.github.com/en/articles/about-code-owners
|
||||
# https://help.github.com/articles/about-code-owners
|
||||
|
||||
* @iCrawl
|
||||
|
||||
/apps/guide/ @discordjs/website @discordjs/guide
|
||||
/apps/guide/src/content/ @discordjs/guide
|
||||
/apps/website/ @discordjs/website
|
||||
|
||||
/packages/actions/ @discordjs/actions
|
||||
/packages/api-extractor-utils/ @discordjs/api-extractor-utils
|
||||
/packages/brokers/ @discordjs/brokers
|
||||
|
||||
3
.github/COMMIT_CONVENTION.md
vendored
@@ -7,7 +7,7 @@
|
||||
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}/;
|
||||
/^(revert: )?(feat|fix|docs|style|refactor|perf|test|build|ci|chore|types)(\(.+\))?!?: .{1,72}/;
|
||||
```
|
||||
|
||||
#### Examples
|
||||
@@ -55,6 +55,7 @@ A commit message consists of a **header**, **body** and **footer**. The header h
|
||||
```
|
||||
|
||||
The **header** is mandatory and the **scope** of the header is optional.
|
||||
If the commit contains **Breaking Changes**, a `!` can be added before the `:` as an indicator.
|
||||
|
||||
### Revert
|
||||
|
||||
|
||||
80
.github/labeler.yml
vendored
@@ -1,60 +1,100 @@
|
||||
apps:guide:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['apps/guide/*', 'apps/guide/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- apps/guide/*
|
||||
- apps/guide/**/*
|
||||
apps:website:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['apps/website/*', 'apps/website/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- apps/website/*
|
||||
- apps/website/**/*
|
||||
packages:api-extractor:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/api-extractor/*', 'packages/api-extractor/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/api-extractor/*
|
||||
- packages/api-extractor/**/*
|
||||
packages:api-extractor-model:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/api-extractor-model/*', 'packages/api-extractor-model/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/api-extractor-model/*
|
||||
- packages/api-extractor-model/**/*
|
||||
packages:brokers:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/brokers/*', 'packages/brokers/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/brokers/*
|
||||
- packages/brokers/**/*
|
||||
packages:builders:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/builders/*', 'packages/builders/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/builders/*
|
||||
- packages/builders/**/*
|
||||
packages:collection:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/collection/*', 'packages/collection/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/collection/*
|
||||
- packages/collection/**/*
|
||||
packages:core:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/core/*', 'packages/core/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/core/*
|
||||
- packages/core/**/*
|
||||
packages:create-discord-bot:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/create-discord-bot/*', 'packages/create-discord-bot/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/create-discord-bot/*
|
||||
- packages/create-discord-bot/**/*
|
||||
packages:discord.js:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/discord.js/*', 'packages/discord.js/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/discord.js/*
|
||||
- packages/discord.js/**/*
|
||||
packages:docgen:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/docgen/*', 'packages/docgen/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/docgen/*
|
||||
- packages/docgen/**/*
|
||||
packages:formatters:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/formatters/*', 'packages/formatters/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/formatters/*
|
||||
- packages/formatters/**/*
|
||||
packages:next:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/next/*', 'packages/next/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/next/*
|
||||
- packages/next/**/*
|
||||
packages:proxy:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/proxy/*', 'packages/proxy/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/proxy/*
|
||||
- packages/proxy/**/*
|
||||
packages:proxy-container:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/proxy-container/*', 'packages/proxy-container/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/proxy-container/*
|
||||
- packages/proxy-container/**/*
|
||||
packages:rest:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/rest/*', 'packages/rest/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/rest/*
|
||||
- packages/rest/**/*
|
||||
packages:ui:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/ui/*', 'packages/ui/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/ui/*
|
||||
- packages/ui/**/*
|
||||
packages:util:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/util/*', 'packages/util/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/util/*
|
||||
- packages/util/**/*
|
||||
packages:voice:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/voice/*', 'packages/voice/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/voice/*
|
||||
- packages/voice/**/*
|
||||
packages:ws:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['packages/ws/*', 'packages/ws/**/*']
|
||||
- any-glob-to-any-file:
|
||||
- packages/ws/*
|
||||
- packages/ws/**/*
|
||||
|
||||
2
.github/workflows/cleanup-cache.yml
vendored
@@ -1,4 +1,4 @@
|
||||
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
|
||||
# https://docs.github.com/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
|
||||
name: Cleanup caches
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
34
.github/workflows/deploy-website.yml
vendored
@@ -1,34 +0,0 @@
|
||||
name: Deploy website
|
||||
on:
|
||||
workflow_dispatch:
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
|
||||
cancel-in-progress: true
|
||||
jobs:
|
||||
deploy-website:
|
||||
name: Deploy website
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
|
||||
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
|
||||
if: github.repository_owner == 'discordjs'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Node.js v20
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- name: Install dependencies
|
||||
uses: ./packages/actions/src/pnpmCache
|
||||
|
||||
- name: Pull vercel production environment
|
||||
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
|
||||
|
||||
- name: Build website artifacts
|
||||
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
|
||||
|
||||
- name: Deploy website artifacts to vercel
|
||||
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
|
||||
97
.github/workflows/documentation.yml
vendored
@@ -1,8 +1,6 @@
|
||||
name: Documentation
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
paths:
|
||||
- 'packages/*/src/**'
|
||||
- '!packages/create-discord-bot/**'
|
||||
@@ -13,14 +11,7 @@ on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
ref:
|
||||
description: 'The branch, tag or SHA to checkout'
|
||||
required: true
|
||||
ref_type:
|
||||
type: choice
|
||||
description: 'Branch or tag'
|
||||
options:
|
||||
- branch
|
||||
- tag
|
||||
description: 'The tag to checkout'
|
||||
required: true
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
|
||||
@@ -32,7 +23,6 @@ jobs:
|
||||
env:
|
||||
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
|
||||
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
|
||||
REF_TYPE: ${{ inputs.ref_type || github.ref_type }}
|
||||
if: github.repository_owner == 'discordjs'
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
@@ -52,13 +42,11 @@ jobs:
|
||||
run: pnpm run build
|
||||
|
||||
- name: Checkout main repository
|
||||
if: ${{ inputs.ref && inputs.ref != 'main' }}
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: 'main'
|
||||
|
||||
- name: Build main
|
||||
if: ${{ inputs.ref && inputs.ref != 'main' }}
|
||||
shell: bash
|
||||
run: |
|
||||
cd main
|
||||
@@ -67,26 +55,20 @@ jobs:
|
||||
cd ..
|
||||
|
||||
- name: Extract package and semver from tag
|
||||
if: ${{ env.REF_TYPE == 'tag' }}
|
||||
id: extract-tag
|
||||
uses: ./packages/actions/src/formatTag
|
||||
with:
|
||||
tag: ${{ inputs.ref || github.ref_name }}
|
||||
|
||||
- name: Apply tag to api-extractor config
|
||||
if: ${{ env.REF_TYPE == 'tag' && !inputs.ref }}
|
||||
run: sed -i 's!https://github.com/discordjs/discord.js/tree/main!https://github.com/discordjs/discord.js/tree/${{ steps.extract-tag.outputs.semver }}!' "packages/${{ steps.extract-tag.outputs.package}}/api-extractor.json"
|
||||
|
||||
- name: Build docs
|
||||
run: pnpm run docs
|
||||
|
||||
- name: Build docs with main api-extractor
|
||||
if: ${{ inputs.ref && inputs.ref != 'main' }}
|
||||
run: |
|
||||
declare -a PACKAGES=("brokers" "builders" "collection" "core" "discord.js" "formatters" "next" "proxy" "rest" "util" "voice" "ws")
|
||||
for PACKAGE in "${PACKAGES[@]}"; do
|
||||
cd "packages/${PACKAGE}"
|
||||
sed -i 's!https://github.com/discordjs/discord.js/tree/main!https://github.com/discordjs/discord.js/tree/${{ inputs.ref }}!' api-extractor.json
|
||||
sed -i 's!https://github.com/discordjs/discord.js/tree/main!https://github.com/discordjs/discord.js/tree/${{ inputs.ref || github.ref_name }}!' api-extractor.json
|
||||
../../main/packages/api-extractor/bin/api-extractor run --local --minify
|
||||
../../main/packages/scripts/bin/generateSplitDocumentation.js
|
||||
cd ../..
|
||||
@@ -100,45 +82,35 @@ jobs:
|
||||
path: 'out'
|
||||
|
||||
- name: Upload documentation to database
|
||||
if: ${{ env.REF_TYPE == 'tag' && (!inputs.ref || inputs.ref == 'main') }}
|
||||
env:
|
||||
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
||||
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
|
||||
uses: ./packages/actions/src/uploadDocumentation
|
||||
with:
|
||||
package: ${{ steps.extract-tag.outputs.package }}
|
||||
version: ${{ steps.extract-tag.outputs.semver }}
|
||||
|
||||
- name: Upload documentation to database
|
||||
if: ${{ env.REF_TYPE == 'tag' && inputs.ref && inputs.ref != 'main' }}
|
||||
env:
|
||||
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
||||
CF_D1_DOCS_API_KEY: ${{ secrets.CF_D1_DOCS_API_KEY }}
|
||||
CF_D1_DOCS_ID: ${{ secrets.CF_D1_DOCS_ID }}
|
||||
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
|
||||
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
|
||||
CF_R2_DOCS_URL: ${{ secrets.CF_R2_DOCS_URL }}
|
||||
CF_R2_DOCS_ACCESS_KEY_ID: ${{ secrets.CF_R2_DOCS_ACCESS_KEY_ID }}
|
||||
CF_R2_DOCS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_DOCS_SECRET_ACCESS_KEY }}
|
||||
CF_R2_DOCS_BUCKET: ${{ secrets.CF_R2_DOCS_BUCKET }}
|
||||
CF_R2_DOCS_BUCKET_URL: ${{ secrets.CF_R2_DOCS_BUCKET_URL }}
|
||||
uses: ./main/packages/actions/src/uploadDocumentation
|
||||
with:
|
||||
package: ${{ steps.extract-tag.outputs.package }}
|
||||
version: ${{ steps.extract-tag.outputs.semver }}
|
||||
|
||||
- name: Upload split documentation to blob storage
|
||||
if: ${{ env.REF_TYPE == 'tag' && (!inputs.ref || inputs.ref == 'main') }}
|
||||
env:
|
||||
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
|
||||
uses: ./packages/actions/src/uploadSplitDocumentation
|
||||
with:
|
||||
package: ${{ steps.extract-tag.outputs.package }}
|
||||
version: ${{ steps.extract-tag.outputs.semver }}
|
||||
|
||||
- name: Upload split documentation to blob storage
|
||||
if: ${{ env.REF_TYPE == 'tag' && inputs.ref && inputs.ref != 'main' }}
|
||||
env:
|
||||
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
|
||||
CF_R2_DOCS_URL: ${{ secrets.CF_R2_DOCS_URL }}
|
||||
CF_R2_DOCS_ACCESS_KEY_ID: ${{ secrets.CF_R2_DOCS_ACCESS_KEY_ID }}
|
||||
CF_R2_DOCS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_DOCS_SECRET_ACCESS_KEY }}
|
||||
CF_R2_DOCS_BUCKET: ${{ secrets.CF_R2_DOCS_BUCKET }}
|
||||
uses: ./main/packages/actions/src/uploadSplitDocumentation
|
||||
with:
|
||||
package: ${{ steps.extract-tag.outputs.package }}
|
||||
version: ${{ steps.extract-tag.outputs.semver }}
|
||||
|
||||
- name: Move docs to correct directory
|
||||
if: ${{ env.REF_TYPE == 'tag' }}
|
||||
env:
|
||||
PACKAGE: ${{ steps.extract-tag.outputs.package }}
|
||||
SEMVER: ${{ steps.extract-tag.outputs.semver }}
|
||||
@@ -151,47 +123,6 @@ jobs:
|
||||
mv "packages/${PACKAGE}/docs/docs.api.json" "out/${PACKAGE}/${SEMVER}.api.json"
|
||||
fi
|
||||
|
||||
- name: Upload documentation to database
|
||||
if: ${{ env.REF_TYPE == 'branch' && (!inputs.ref || inputs.ref == 'main') }}
|
||||
env:
|
||||
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
||||
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
|
||||
uses: ./packages/actions/src/uploadDocumentation
|
||||
|
||||
- name: Upload documentation to database
|
||||
if: ${{ env.REF_TYPE == 'branch' && inputs.ref && inputs.ref != 'main' }}
|
||||
env:
|
||||
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
||||
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
|
||||
uses: ./main/packages/actions/src/uploadDocumentation
|
||||
|
||||
- name: Upload split documentation to blob storage
|
||||
if: ${{ env.REF_TYPE == 'branch' && (!inputs.ref || inputs.ref == 'main') }}
|
||||
env:
|
||||
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
|
||||
uses: ./packages/actions/src/uploadSplitDocumentation
|
||||
|
||||
- name: Upload split documentation to blob storage
|
||||
if: ${{ env.REF_TYPE == 'branch' && inputs.ref && inputs.ref != 'main' }}
|
||||
env:
|
||||
BLOB_READ_WRITE_TOKEN: ${{ secrets.BLOB_READ_WRITE_TOKEN }}
|
||||
uses: ./main/packages/actions/src/uploadSplitDocumentation
|
||||
|
||||
- name: Move docs to correct directory
|
||||
if: ${{ env.REF_TYPE == 'branch' }}
|
||||
run: |
|
||||
declare -a PACKAGES=("brokers" "builders" "collection" "core" "discord.js" "formatters" "next" "proxy" "rest" "util" "voice" "ws")
|
||||
for PACKAGE in "${PACKAGES[@]}"; do
|
||||
if [[ "${PACKAGE}" == "discord.js" ]]; then
|
||||
mkdir -p "out/${PACKAGE}"
|
||||
mv "packages/${PACKAGE}/docs/docs.json" "out/${PACKAGE}/${GITHUB_REF_NAME}.json"
|
||||
mv "packages/${PACKAGE}/docs/docs.api.json" "out/${PACKAGE}/${GITHUB_REF_NAME}.api.json"
|
||||
else
|
||||
mkdir -p "out/${PACKAGE}"
|
||||
mv "packages/${PACKAGE}/docs/docs.api.json" "out/${PACKAGE}/${GITHUB_REF_NAME}.api.json"
|
||||
fi
|
||||
done
|
||||
|
||||
- name: Commit and push
|
||||
run: |
|
||||
cd out
|
||||
|
||||
28
.github/workflows/pr-triage.yml
vendored
@@ -1,13 +1,35 @@
|
||||
name: 'PR Triage'
|
||||
on:
|
||||
pull_request_target:
|
||||
types:
|
||||
- opened
|
||||
- edited
|
||||
- reopened
|
||||
- synchronize
|
||||
jobs:
|
||||
pr-triage:
|
||||
name: PR Triage
|
||||
label:
|
||||
name: Label
|
||||
if: github.event.action != 'edited'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Automatically label PR
|
||||
- name: Label pull request
|
||||
uses: actions/labeler@v5
|
||||
with:
|
||||
repo-token: '${{ secrets.GITHUB_TOKEN }}'
|
||||
sync-labels: true
|
||||
validate-title:
|
||||
name: Validate title
|
||||
if: github.event.action != 'synchronize'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Validate pull request title
|
||||
env:
|
||||
TITLE: ${{ github.event.pull_request.title }}
|
||||
run: |
|
||||
REGEX="^(revert: )?(feat|fix|docs|style|refactor|perf|test|build|ci|chore|types)(\\(.+\\))?!?: .{1,72}$"
|
||||
|
||||
echo "Title: \"$TITLE\""
|
||||
|
||||
if [[ ! "$TITLE" =~ $REGEX ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
2
.github/workflows/publish-dev.yml
vendored
@@ -72,7 +72,7 @@ jobs:
|
||||
- name: Publish package
|
||||
if: steps.release-check.outputs.release == '1'
|
||||
run: |
|
||||
pnpm --filter=${{ matrix.package }} run release --preid "dev.$(date +%s)-$(git rev-parse --short HEAD)"
|
||||
pnpm --filter=${{ matrix.package }} run release --preid "dev.$(date +%s)-$(git rev-parse --short HEAD)" --skip-changelog
|
||||
pnpm --filter=${{ matrix.package }} publish --provenance --no-git-checks --tag dev || true
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
|
||||
|
||||
10
.vscode/settings.json
vendored
@@ -1,11 +1,7 @@
|
||||
{
|
||||
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
|
||||
"eslint.experimental.useFlatConfig": true,
|
||||
"eslint.workingDirectories": [
|
||||
{ "directory": "${workspaceFolder}" },
|
||||
{ "pattern": "./apps/*/" },
|
||||
{ "pattern": "./packages/*/" }
|
||||
],
|
||||
"eslint.useFlatConfig": true,
|
||||
"eslint.workingDirectories": [{ "directory": "${workspaceFolder}" }, { "pattern": "./packages/*/" }],
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true,
|
||||
"editor.codeActionsOnSave": {
|
||||
@@ -30,6 +26,6 @@
|
||||
"deno.enable": false,
|
||||
"deno.enablePaths": ["./packages/create-discord-bot/template/Deno"],
|
||||
"deno.lint": false,
|
||||
"deno.unstable": false,
|
||||
"deno.unstable": [],
|
||||
"deno.config": "./packages/create-discord-bot/template/Deno/deno.jsonc"
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
<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/actions/workflows/test.yml/badge.svg" alt="Tests status" /></a>
|
||||
<a href="https://codecov.io/gh/discordjs/discord.js" ><img src="https://codecov.io/gh/discordjs/discord.js/branch/main/graph/badge.svg?precision=2" alt="Code coverage" /></a>
|
||||
<a href="https://github.com/discordjs/discord.js/commits/main"><img src="https://img.shields.io/github/last-commit/discordjs/discord.js.svg?logo=github&logoColor=ffffff" alt="Last commit." /></a>
|
||||
<a href="https://github.com/discordjs/discord.js/graphs/contributors"><img src="https://img.shields.io/github/contributors/discordjs/discord.js.svg?maxAge=3600&logo=github&logoColor=fff&color=00c7be" alt="contributors" /></a>
|
||||
<a href="https://codecov.io/gh/discordjs/discord.js"><img src="https://codecov.io/gh/discordjs/discord.js/branch/main/graph/badge.svg?precision=2" alt="Code coverage" /></a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a>
|
||||
|
||||
@@ -107,7 +107,7 @@
|
||||
"allowArbitraryExtensions": false,
|
||||
"allowImportingTsExtensions": false,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "nodenext",
|
||||
"moduleResolution": "Bundler",
|
||||
"resolveJsonModule": true,
|
||||
"resolvePackageJsonExports": false,
|
||||
"resolvePackageJsonImports": false,
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
METADATA_BASE_URL=http://localhost:3000
|
||||
@@ -1,7 +0,0 @@
|
||||
.contentlayer
|
||||
.next
|
||||
.turbo
|
||||
.vscode
|
||||
coverage
|
||||
src/styles/unocss.css
|
||||
next-env.d.ts
|
||||
@@ -1,52 +0,0 @@
|
||||
<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://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Build status" /></a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a>
|
||||
<a href="https://www.cloudflare.com"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-workers.png" alt="Cloudflare Workers" height="44" /></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
## About
|
||||
|
||||
The official guide for discord.js, made to help you get started easily with the library.
|
||||
|
||||
## Links
|
||||
|
||||
- [Website][website] ([source][website-source])
|
||||
- [Documentation][documentation]
|
||||
- [Guide][guide] ([source][guide-source])
|
||||
Also see the v13 to v14 [Update Guide][guide-update], which includes updated and removed items from the library.
|
||||
- [discord.js Discord server][discord]
|
||||
- [Discord API Discord server][discord-api]
|
||||
- [GitHub][source]
|
||||
- [Related libraries][related-libs]
|
||||
|
||||
## Contributing
|
||||
|
||||
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
|
||||
[documentation][documentation].
|
||||
See [the contribution guide][contributing] 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][discord].
|
||||
|
||||
[website]: https://discord.js.org
|
||||
[website-source]: https://github.com/discordjs/discord.js/tree/main/apps/website
|
||||
[documentation]: https://discord.js.org/docs
|
||||
[guide]: https://discordjs.guide/
|
||||
[guide-source]: https://github.com/discordjs/guide
|
||||
[guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html
|
||||
[discord]: https://discord.gg/djs
|
||||
[discord-api]: https://discord.gg/discord-api
|
||||
[source]: https://github.com/discordjs/discord.js/tree/main/apps/guide
|
||||
[related-libs]: https://discord.com/developers/docs/topics/community-resources#libraries
|
||||
[contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md
|
||||
@@ -1,94 +0,0 @@
|
||||
import { remarkCodeHike } from '@code-hike/mdx';
|
||||
import { defineDocumentType, makeSource } from 'contentlayer/source-files';
|
||||
import { type Node, toString } from 'hast-util-to-string';
|
||||
import { h } from 'hastscript';
|
||||
import { escape } from 'html-escaper';
|
||||
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
|
||||
import rehypeSlug from 'rehype-slug';
|
||||
import remarkGfm from 'remark-gfm';
|
||||
import codeHikeThemeDarkPlus from './src/styles/code-hike-theme-dark-plus.json';
|
||||
|
||||
export const Content = defineDocumentType(() => ({
|
||||
name: 'Content',
|
||||
filePathPattern: `**/*.mdx`,
|
||||
contentType: 'mdx',
|
||||
fields: {
|
||||
title: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
category: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
computedFields: {
|
||||
slug: {
|
||||
type: 'string',
|
||||
// eslint-disable-next-line unicorn/prefer-string-replace-all
|
||||
resolve: (doc) => doc._raw.flattenedPath.replace(/\d+-/g, ''),
|
||||
},
|
||||
url: {
|
||||
type: 'string',
|
||||
// eslint-disable-next-line unicorn/prefer-string-replace-all
|
||||
resolve: (doc) => `/guide/${doc._raw.flattenedPath.replace(/\d+-/g, '')}`,
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
const LinkIcon = h(
|
||||
'svg',
|
||||
{
|
||||
width: '1.25rem',
|
||||
height: '1.25rem',
|
||||
viewBox: '0 0 24 24',
|
||||
fill: 'none',
|
||||
stroke: 'currentColor',
|
||||
strokeWidth: '2',
|
||||
strokeLinecap: 'round',
|
||||
strokeLinejoin: 'round',
|
||||
},
|
||||
h('path', {
|
||||
// eslint-disable-next-line id-length
|
||||
d: 'M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71',
|
||||
}),
|
||||
h('path', {
|
||||
// eslint-disable-next-line id-length
|
||||
d: 'M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71',
|
||||
}),
|
||||
);
|
||||
|
||||
const createSROnlyLabel = (text: any) => {
|
||||
return h('span', { class: 'sr-only' }, `Section titled ${escape(text)}`);
|
||||
};
|
||||
|
||||
export default makeSource({
|
||||
contentDirPath: 'src/content',
|
||||
documentTypes: [Content],
|
||||
mdx: {
|
||||
remarkPlugins: [remarkGfm, [remarkCodeHike, { theme: codeHikeThemeDarkPlus, lineNumbers: true }]],
|
||||
rehypePlugins: [
|
||||
rehypeSlug,
|
||||
[
|
||||
rehypeAutolinkHeadings,
|
||||
{
|
||||
properties: {
|
||||
class:
|
||||
'relative inline-flex place-items-center place-content-center outline-none text-black dark:text-white pr-2 -ml-8 opacity-0 group-hover:opacity-100',
|
||||
},
|
||||
behavior: 'prepend',
|
||||
content: (heading: Node) => [
|
||||
h(
|
||||
`span.anchor-icon`,
|
||||
{
|
||||
ariaHidden: 'true',
|
||||
},
|
||||
LinkIcon,
|
||||
),
|
||||
createSROnlyLabel(toString(heading)),
|
||||
],
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
});
|
||||
5
apps/guide/next-env.d.ts
vendored
@@ -1,5 +0,0 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
@@ -1,17 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||
// import { withContentlayer } from 'next-contentlayer';
|
||||
const { withContentlayer } = require('next-contentlayer');
|
||||
|
||||
module.exports = withContentlayer({
|
||||
reactStrictMode: true,
|
||||
experimental: {
|
||||
typedRoutes: true,
|
||||
},
|
||||
images: {
|
||||
dangerouslyAllowSVG: true,
|
||||
contentDispositionType: 'attachment',
|
||||
contentSecurityPolicy: "default-src 'self'; frame-src 'none'; sandbox;",
|
||||
},
|
||||
poweredByHeader: false,
|
||||
});
|
||||
@@ -1,99 +0,0 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "@discordjs/guide",
|
||||
"version": "0.1.0",
|
||||
"description": "Imagine a guide... that explores the many possibilities for your discord.js bot",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"build:check": "tsc --noEmit",
|
||||
"build:local": "pnpm run build:prod",
|
||||
"build:prod": "next build",
|
||||
"build:analyze": "cross-env ANALYZE=true pnpm run build:prod",
|
||||
"preview": "next start",
|
||||
"dev": "next dev",
|
||||
"generate:contentlayer": "contentlayer build",
|
||||
"lint": "pnpm run build:check && prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
|
||||
"format": "pnpm run build:check && prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
|
||||
"fmt": "pnpm run format"
|
||||
},
|
||||
"type": "commonjs",
|
||||
"directories": {
|
||||
"lib": "src"
|
||||
},
|
||||
"contributors": [
|
||||
"Crawl <icrawltogo@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"discord",
|
||||
"api",
|
||||
"bot",
|
||||
"client",
|
||||
"node",
|
||||
"discordapp",
|
||||
"discordjs"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/discordjs/discord.js.git",
|
||||
"directory": "apps/guide"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/discordjs/discord.js/issues"
|
||||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"funding": "https://github.com/discordjs/discord.js?sponsor",
|
||||
"dependencies": {
|
||||
"@code-hike/mdx": "^0.9.0",
|
||||
"@discordjs/ui": "workspace:^",
|
||||
"@react-icons/all-files": "^4.1.0",
|
||||
"@vercel/analytics": "^1.2.2",
|
||||
"@vercel/edge-config": "^1.1.0",
|
||||
"@vercel/og": "^0.6.2",
|
||||
"ariakit": "2.0.0-next.44",
|
||||
"cmdk": "^1.0.0",
|
||||
"contentlayer": "^0.3.4",
|
||||
"next": "^14.2.3",
|
||||
"next-contentlayer": "^0.3.4",
|
||||
"next-themes": "^0.3.0",
|
||||
"react": "^18.3.1",
|
||||
"react-custom-scrollbars-2": "^4.5.0",
|
||||
"react-dom": "^18.3.1",
|
||||
"rehype-autolink-headings": "^6.1.1",
|
||||
"rehype-slug": "^5.1.0",
|
||||
"remark-gfm": "^3.0.1",
|
||||
"sharp": "^0.33.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/react": "^15.0.7",
|
||||
"@testing-library/user-event": "^14.5.2",
|
||||
"@types/html-escaper": "^3.0.2",
|
||||
"@types/node": "18.18.8",
|
||||
"@types/react": "^18.3.3",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
"@unocss/eslint-plugin": "^0.60.2",
|
||||
"@unocss/postcss": "^0.60.2",
|
||||
"@unocss/reset": "^0.60.2",
|
||||
"@vitejs/plugin-react": "^4.2.1",
|
||||
"@vitest/coverage-v8": "^1.6.0",
|
||||
"cross-env": "^7.0.3",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-neon": "^0.1.62",
|
||||
"eslint-formatter-pretty": "^6.0.1",
|
||||
"happy-dom": "^14.11.0",
|
||||
"hast-util-to-string": "^2.0.0",
|
||||
"hastscript": "^8.0.0",
|
||||
"html-escaper": "^3.0.3",
|
||||
"postcss": "^8.4.38",
|
||||
"prettier": "^3.2.5",
|
||||
"turbo": "^1.13.2",
|
||||
"typescript": "^5.4.5",
|
||||
"unocss": "^0.60.2",
|
||||
"vercel": "^34.0.0",
|
||||
"vitest": "^1.5.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
'@unocss/postcss': {},
|
||||
},
|
||||
};
|
||||
|
Before Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 7.6 KiB |
|
Before Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 8.8 KiB |
|
Before Width: | Height: | Size: 182 KiB |
|
Before Width: | Height: | Size: 115 KiB |
|
Before Width: | Height: | Size: 290 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 164 KiB |
|
Before Width: | Height: | Size: 53 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 9.0 KiB |
|
Before Width: | Height: | Size: 76 KiB |
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<browserconfig>
|
||||
<msapplication>
|
||||
<tile>
|
||||
<square70x70logo src="/mstile-70x70.png"/>
|
||||
<square150x150logo src="/mstile-150x150.png"/>
|
||||
<square310x310logo src="/mstile-310x310.png"/>
|
||||
<wide310x150logo src="/mstile-310x150.png"/>
|
||||
<TileColor>#090a16</TileColor>
|
||||
</tile>
|
||||
</msapplication>
|
||||
</browserconfig>
|
||||
|
Before Width: | Height: | Size: 561 B |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 2.6 KiB |
|
Before Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 5.2 KiB |
@@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
|
||||
width="400.000000pt" height="400.000000pt" viewBox="0 0 400.000000 400.000000"
|
||||
preserveAspectRatio="xMidYMid meet">
|
||||
<metadata>
|
||||
Created by potrace 1.14, written by Peter Selinger 2001-2017
|
||||
</metadata>
|
||||
<g transform="translate(0.000000,400.000000) scale(0.100000,-0.100000)"
|
||||
fill="#000000" stroke="none">
|
||||
<path d="M0 2000 l0 -2000 2000 0 2000 0 0 2000 0 2000 -2000 0 -2000 0 0
|
||||
-2000z m1305 795 c219 -47 373 -197 421 -411 24 -109 16 -315 -16 -399 l-23
|
||||
-61 -59 -11 c-110 -21 -182 -92 -203 -202 -11 -56 -11 -56 -68 -79 -76 -30
|
||||
-201 -42 -464 -42 l-223 0 0 610 0 610 283 0 c210 0 300 -4 352 -15z m890
|
||||
-585 c0 -543 -2 -601 -18 -659 -56 -198 -190 -334 -365 -370 -176 -37 -349 5
|
||||
-471 115 -48 44 -111 134 -111 161 0 6 19 14 43 18 23 4 73 18 110 32 l68 24
|
||||
50 -45 c56 -50 98 -66 175 -66 100 0 207 81 234 178 6 23 10 251 10 625 l0
|
||||
588 138 -3 137 -3 0 -595z m930 570 c93 -29 197 -84 252 -134 l44 -41 -61 -75
|
||||
c-34 -41 -67 -81 -74 -88 -10 -10 -25 -4 -78 32 -95 63 -154 81 -268 81 -79 0
|
||||
-103 -4 -142 -23 -62 -31 -90 -71 -96 -137 -8 -94 28 -137 168 -202 157 -73
|
||||
172 -80 240 -108 236 -97 341 -215 356 -400 16 -193 -82 -363 -258 -449 -91
|
||||
-45 -187 -66 -303 -66 -191 0 -390 74 -524 195 l-40 37 80 93 80 94 73 -53
|
||||
c168 -121 353 -155 491 -92 72 33 108 82 113 155 9 122 -37 162 -323 286 -258
|
||||
111 -350 179 -407 300 -69 148 -37 343 75 463 61 65 195 133 300 152 79 14
|
||||
222 4 302 -20z m-1367 -977 c45 -34 65 -69 70 -125 4 -61 -19 -106 -77 -145
|
||||
-90 -60 -226 3 -238 111 -3 24 -3 56 1 70 8 34 54 86 91 102 40 19 120 12 153
|
||||
-13z"/>
|
||||
<path d="M967 2543 c-4 -3 -7 -159 -7 -346 l0 -339 128 4 c101 3 136 8 172 24
|
||||
106 48 162 145 168 292 10 214 -69 334 -238 361 -73 12 -213 15 -223 4z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 1.8 KiB |
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"name": "discord.js guide",
|
||||
"short_name": "discord.js guide",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/android-chrome-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/android-chrome-384x384.png",
|
||||
"sizes": "384x384",
|
||||
"type": "image/png"
|
||||
}
|
||||
],
|
||||
"theme_color": "#1a1b1e",
|
||||
"background_color": "#1a1b1e",
|
||||
"display": "standalone"
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { inter } from '~/util/fonts';
|
||||
import { Providers } from './providers';
|
||||
|
||||
import '~/styles/cmdk.css';
|
||||
import '~/styles/main.css';
|
||||
|
||||
export default function GlobalError({ error }: { readonly error: Error }) {
|
||||
console.error(error);
|
||||
|
||||
return (
|
||||
<html className={inter.variable} lang="en" suppressHydrationWarning>
|
||||
<body className="bg-light-600 dark:bg-dark-600 dark:text-light-900">
|
||||
<Providers>
|
||||
<main className="mx-auto max-w-2xl min-h-screen">
|
||||
<div className="mx-auto max-w-lg min-h-screen flex flex-col place-content-center place-items-center gap-8 px-8 py-16 lg:px-6 lg:py-0">
|
||||
<h1 className="text-[9rem] font-black leading-none md:text-[12rem]">500</h1>
|
||||
<h2 className="text-[2rem] md:text-[3rem]">Error.</h2>
|
||||
</div>
|
||||
</main>
|
||||
</Providers>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
'use client';
|
||||
|
||||
export default function Error({ error }: { readonly error: Error }) {
|
||||
console.error(error);
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-lg min-h-screen flex flex-col place-content-center place-items-center gap-8 px-8 py-16 lg:px-6 lg:py-0">
|
||||
<h1 className="text-[9rem] font-black leading-none md:text-[12rem]">500</h1>
|
||||
<h2 className="text-[2rem] md:text-[3rem]">Error.</h2>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export { default } from '~/app/not-found';
|
||||
@@ -1,21 +0,0 @@
|
||||
import { notFound } from 'next/navigation';
|
||||
import { allContents } from 'contentlayer/generated';
|
||||
import { Mdx } from '~/components/Mdx';
|
||||
|
||||
export async function generateStaticParams() {
|
||||
return allContents.map((content) => ({ slug: [content.slug] }));
|
||||
}
|
||||
|
||||
export default function Page({ params }: { readonly params: { slug: string[] } }) {
|
||||
const content = allContents.find((content) => content.slug === params.slug?.join('/'));
|
||||
|
||||
if (!content) {
|
||||
notFound();
|
||||
}
|
||||
|
||||
return (
|
||||
<article className="max-w-none px-5 prose">
|
||||
<Mdx code={content?.body.code ?? ''} />
|
||||
</article>
|
||||
);
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import Footer from '~/components/Footer';
|
||||
import Header from '~/components/Header';
|
||||
import { Nav } from '~/components/Nav';
|
||||
import { Providers } from './providers';
|
||||
|
||||
export default function Layout({ children }: PropsWithChildren) {
|
||||
return (
|
||||
<Providers>
|
||||
<main className="mx-auto max-w-7xl px-4 lg:max-w-full">
|
||||
<Header />
|
||||
<div className="relative top-6 mx-auto max-w-7xl gap-6 lg:max-w-full lg:flex">
|
||||
<div className="lg:sticky lg:top-23 lg:h-[calc(100vh_-_105px)]">
|
||||
<Nav />
|
||||
</div>
|
||||
|
||||
<div className="mx-auto max-w-5xl min-w-xs w-full pb-10">
|
||||
{children}
|
||||
<Footer />
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</Providers>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export default function Page() {
|
||||
return null;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import { NavProvider } from '~/contexts/nav';
|
||||
|
||||
export function Providers({ children }: PropsWithChildren) {
|
||||
return <NavProvider>{children}</NavProvider>;
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
import { Analytics } from '@vercel/analytics/react';
|
||||
import type { Metadata, Viewport } from 'next';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import { DESCRIPTION } from '~/util/constants';
|
||||
import { inter, jetBrainsMono } from '~/util/fonts';
|
||||
import { Providers } from './providers';
|
||||
|
||||
import '~/styles/cmdk.css';
|
||||
import '@code-hike/mdx/styles.css';
|
||||
import '~/styles/ch.css';
|
||||
import '~/styles/main.css';
|
||||
|
||||
export const viewport: Viewport = {
|
||||
themeColor: [
|
||||
{ media: '(prefers-color-scheme: light)', color: '#f1f3f5' },
|
||||
{ media: '(prefers-color-scheme: dark)', color: '#181818' },
|
||||
],
|
||||
colorScheme: 'light dark',
|
||||
};
|
||||
|
||||
export const metadata: Metadata = {
|
||||
metadataBase: new URL(
|
||||
process.env.METADATA_BASE_URL ? process.env.METADATA_BASE_URL : `http://localhost:${process.env.PORT ?? 3_000}`,
|
||||
),
|
||||
title: 'discord.js',
|
||||
description: DESCRIPTION,
|
||||
icons: {
|
||||
other: [
|
||||
{
|
||||
url: '/favicon-32x32.png',
|
||||
sizes: '32x32',
|
||||
type: 'image/png',
|
||||
},
|
||||
{
|
||||
url: '/favicon-16x16.png',
|
||||
sizes: '16x16',
|
||||
type: 'image/png',
|
||||
},
|
||||
],
|
||||
apple: [
|
||||
'/apple-touch-icon.png',
|
||||
{
|
||||
url: '/safari-pinned-tab.svg',
|
||||
rel: 'mask-icon',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
manifest: '/site.webmanifest',
|
||||
|
||||
appleWebApp: {
|
||||
title: 'discord.js',
|
||||
},
|
||||
|
||||
applicationName: 'discord.js',
|
||||
|
||||
openGraph: {
|
||||
siteName: 'discord.js',
|
||||
type: 'website',
|
||||
title: 'discord.js',
|
||||
description: DESCRIPTION,
|
||||
images: 'https://discordjs.dev/api/open-graph.png',
|
||||
},
|
||||
|
||||
twitter: {
|
||||
card: 'summary_large_image',
|
||||
creator: '@iCrawlToGo',
|
||||
},
|
||||
|
||||
other: {
|
||||
'msapplication-TileColor': '#090a16',
|
||||
},
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: PropsWithChildren) {
|
||||
return (
|
||||
<html className={`${inter.variable} ${jetBrainsMono.variable}`} lang="en" suppressHydrationWarning>
|
||||
<body className="bg-light-600 dark:bg-dark-600 dark:text-light-900">
|
||||
<Providers>{children}</Providers>
|
||||
<Analytics />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
export default function Loading() {
|
||||
return (
|
||||
<div className="mx-4 min-h-screen flex flex-col items-center justify-center gap-4">
|
||||
<svg
|
||||
className="h-9 w-9 animate-spin text-black dark:text-white"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
|
||||
<path
|
||||
className="opacity-75 dark:opacity-100"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
</svg>
|
||||
<div className="text-lg font-medium">Loading...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import Link from 'next/link';
|
||||
|
||||
export default function NotFound() {
|
||||
return (
|
||||
<div className="mx-auto max-w-lg min-h-screen flex flex-col place-content-center place-items-center gap-8 px-8 py-16 lg:px-6 lg:py-0">
|
||||
<h1 className="text-[9rem] font-black leading-none md:text-[12rem]">404</h1>
|
||||
<h2 className="text-[2rem] md:text-[3rem]">Not found.</h2>
|
||||
<Link
|
||||
className="h-11 flex flex-row transform-gpu cursor-pointer select-none appearance-none place-items-center border-0 rounded bg-blurple px-6 text-base text-white font-semibold leading-none no-underline outline-none active:translate-y-px focus:ring focus:ring-width-2 focus:ring-white"
|
||||
href="/guide"
|
||||
>
|
||||
Take me back
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export default function Page() {
|
||||
return null;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { ThemeProvider } from 'next-themes';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
|
||||
export function Providers({ children }: PropsWithChildren) {
|
||||
return <ThemeProvider attribute="class">{children}</ThemeProvider>;
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="212" height="44" fill="none"><rect width="212" height="44" fill="#000" rx="8"/><path fill="#fff" d="M60.438 15.227V26.5h1.406v-4.023h2.836c2.117 0 3.625-1.493 3.625-3.602 0-2.148-1.477-3.648-3.61-3.648h-4.257Zm1.406 1.25h2.484c1.633 0 2.531.851 2.531 2.398 0 1.492-.93 2.352-2.53 2.352h-2.485v-4.75Zm11.5 10.171c2.399 0 3.883-1.656 3.883-4.359 0-2.71-1.484-4.36-3.883-4.36-2.398 0-3.883 1.65-3.883 4.36 0 2.703 1.485 4.36 3.883 4.36Zm0-1.21c-1.594 0-2.492-1.157-2.492-3.149 0-2 .898-3.148 2.492-3.148 1.594 0 2.492 1.148 2.492 3.148 0 1.992-.898 3.148-2.492 3.148Zm15.954-7.36h-1.352l-1.656 6.735h-.125l-1.883-6.735h-1.29l-1.882 6.735h-.125l-1.656-6.735h-1.36l2.36 8.422h1.36l1.874-6.516h.125l1.883 6.516h1.367l2.36-8.422Zm4.523 1.04c1.336 0 2.227.984 2.258 2.476h-4.64c.101-1.492 1.039-2.477 2.382-2.477Zm2.219 5.202c-.352.742-1.086 1.14-2.172 1.14-1.43 0-2.36-1.054-2.43-2.718v-.062h6.055v-.516c0-2.617-1.383-4.234-3.656-4.234-2.313 0-3.797 1.718-3.797 4.367 0 2.664 1.46 4.351 3.797 4.351 1.844 0 3.156-.89 3.547-2.328H96.04Zm3.242 2.18h1.344v-5.219c0-1.187.93-2.047 2.211-2.047.266 0 .75.047.86.078V17.97a5.77 5.77 0 0 0-.672-.04c-1.117 0-2.086.579-2.336 1.4h-.125v-1.25h-1.281V26.5Zm8.899-7.383c1.336 0 2.227.985 2.258 2.477h-4.641c.102-1.492 1.04-2.477 2.383-2.477Zm2.219 5.203c-.352.742-1.086 1.14-2.172 1.14-1.43 0-2.359-1.054-2.43-2.718v-.062h6.055v-.516c0-2.617-1.383-4.234-3.656-4.234-2.313 0-3.797 1.718-3.797 4.367 0 2.664 1.461 4.351 3.797 4.351 1.844 0 3.156-.89 3.547-2.328H110.4Zm6.36 2.328c1.164 0 2.164-.554 2.695-1.492h.125V26.5h1.281V14.734h-1.343v4.672h-.118c-.476-.922-1.468-1.476-2.64-1.476-2.141 0-3.539 1.718-3.539 4.36 0 2.648 1.382 4.358 3.539 4.358Zm.312-7.507c1.524 0 2.477 1.218 2.477 3.148 0 1.945-.946 3.148-2.477 3.148-1.539 0-2.461-1.18-2.461-3.148 0-1.96.93-3.148 2.461-3.148Zm14.462 7.507c2.133 0 3.531-1.726 3.531-4.359 0-2.648-1.391-4.36-3.531-4.36-1.156 0-2.18.571-2.641 1.477h-.125v-4.672h-1.344V26.5h1.282v-1.344h.125c.531.938 1.531 1.492 2.703 1.492Zm-.313-7.507c1.539 0 2.453 1.18 2.453 3.148 0 1.969-.914 3.148-2.453 3.148-1.531 0-2.484-1.203-2.484-3.148s.953-3.148 2.484-3.148Zm6.04 10.406c1.492 0 2.164-.578 2.882-2.531l3.29-8.938h-1.43l-2.305 6.93h-.125l-2.312-6.93h-1.453l3.117 8.43-.157.5c-.351 1.015-.773 1.383-1.546 1.383-.188 0-.399-.008-.563-.04V29.5c.188.031.422.047.602.047Zm17.391-3.047 3.898-11.273h-2.148l-2.813 8.921h-.132l-2.836-8.921h-2.227l3.938 11.273h2.32Zm8.016-7.18c1.164 0 1.93.813 1.969 2.078h-4.024c.086-1.25.899-2.078 2.055-2.078Zm1.984 4.828c-.281.633-.945.985-1.906.985-1.273 0-2.094-.89-2.141-2.313v-.101h5.969v-.625c0-2.696-1.461-4.313-3.898-4.313-2.477 0-4.016 1.727-4.016 4.477s1.516 4.414 4.031 4.414c2.016 0 3.446-.969 3.797-2.524h-1.836Zm3.547 2.352h1.938v-4.938c0-1.195.875-1.976 2.133-1.976.328 0 .843.055.992.11v-1.798c-.18-.054-.524-.085-.805-.085-1.101 0-2.023.625-2.258 1.468h-.132v-1.328h-1.868V26.5Zm13.501-5.672c-.203-1.797-1.532-3.047-3.727-3.047-2.57 0-4.078 1.649-4.078 4.422 0 2.813 1.516 4.469 4.086 4.469 2.164 0 3.508-1.203 3.719-2.992h-1.844c-.203.89-.875 1.367-1.883 1.367-1.32 0-2.117-1.047-2.117-2.844 0-1.773.789-2.797 2.117-2.797 1.063 0 1.703.594 1.883 1.422h1.844Zm5.117-1.508c1.164 0 1.93.813 1.969 2.078h-4.024c.086-1.25.899-2.078 2.055-2.078Zm1.985 4.828c-.282.633-.946.985-1.907.985-1.273 0-2.093-.89-2.14-2.313v-.101h5.968v-.625c0-2.696-1.461-4.313-3.898-4.313-2.477 0-4.016 1.727-4.016 4.477s1.516 4.414 4.032 4.414c2.015 0 3.445-.969 3.796-2.524h-1.835Zm3.625 2.352h1.937V14.648h-1.937V26.5ZM23.325 13l9.325 16H14l9.325-16Z"/><path stroke="#5E5E5E" d="M43.5 0v44"/></svg>
|
||||
|
Before Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 16 KiB |
@@ -1,91 +0,0 @@
|
||||
import { FiExternalLink } from '@react-icons/all-files/fi/FiExternalLink';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import {
|
||||
BASE_URL_DISCORD_API_TYPES,
|
||||
DISCORD_API_TYPES_VERSION,
|
||||
DISCORD_API_TYPES_VOICE_VERSION,
|
||||
} from '~/util/constants';
|
||||
|
||||
interface DiscordAPITypesLinkOptions {
|
||||
/**
|
||||
* The initial documentation enum, interface, function etc.
|
||||
*
|
||||
* @example `'RESTJSONErrorCodes'`
|
||||
*/
|
||||
readonly parent?: string;
|
||||
/**
|
||||
* The scope of where this link lives.
|
||||
*
|
||||
* @remarks API does not have a scope.
|
||||
*/
|
||||
readonly scope?: 'gateway' | 'globals' | 'payloads' | 'rest' | 'rpc' | 'utils' | 'voice';
|
||||
/**
|
||||
* The symbol belonging to the parent.
|
||||
*
|
||||
* @example '`MaximumNumberOfGuildsReached'`
|
||||
*/
|
||||
readonly symbol?: string;
|
||||
/**
|
||||
* The type of the {@link DiscordAPITypesLinkOptions.parent}.
|
||||
*
|
||||
* @example `'enum'`
|
||||
* @example `'interface'`
|
||||
*/
|
||||
readonly type?: string;
|
||||
}
|
||||
|
||||
export function DiscordAPITypesLink({
|
||||
parent,
|
||||
scope,
|
||||
symbol,
|
||||
type,
|
||||
children,
|
||||
}: PropsWithChildren<DiscordAPITypesLinkOptions>) {
|
||||
let url = BASE_URL_DISCORD_API_TYPES;
|
||||
let text = 'discord-api-types';
|
||||
|
||||
if (type || parent) {
|
||||
url += `/api/discord-api-types`;
|
||||
|
||||
switch (scope) {
|
||||
case 'globals':
|
||||
url += `-${scope}`;
|
||||
break;
|
||||
case 'gateway':
|
||||
case 'payloads':
|
||||
case 'rest':
|
||||
url += `-${scope}/common`;
|
||||
break;
|
||||
case 'rpc':
|
||||
case 'utils':
|
||||
url += `-${scope}/${DISCORD_API_TYPES_VERSION}`;
|
||||
break;
|
||||
case 'voice':
|
||||
url += `-${scope}/${DISCORD_API_TYPES_VOICE_VERSION}`;
|
||||
break;
|
||||
default:
|
||||
url += `-${DISCORD_API_TYPES_VERSION}`;
|
||||
}
|
||||
|
||||
if (type) {
|
||||
url += `/${type}/${parent}`;
|
||||
if (symbol) url += `#${symbol}`;
|
||||
} else {
|
||||
url += `#${parent}`;
|
||||
}
|
||||
|
||||
text = `${parent}${symbol ? `#${symbol}` : ''}${type?.toUpperCase() === 'FUNCTION' ? '()' : ''}`;
|
||||
}
|
||||
|
||||
return (
|
||||
<a
|
||||
className="inline-flex flex-row place-items-center gap-1"
|
||||
href={url}
|
||||
rel="external noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
{children ?? text}
|
||||
<FiExternalLink size={18} />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
import { FiExternalLink } from '@react-icons/all-files/fi/FiExternalLink';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import { BASE_URL, BASE_URL_LEGACY, PACKAGES, VERSION } from '~/util/constants';
|
||||
|
||||
interface DocsLinkOptions {
|
||||
/**
|
||||
* Whether to apply brackets to the end of the symbol to denote a method.
|
||||
*
|
||||
* @remarks Functions automatically infer this.
|
||||
*/
|
||||
readonly brackets?: boolean;
|
||||
/**
|
||||
* The package.
|
||||
*
|
||||
* @defaultValue `'discord.js'`
|
||||
*/
|
||||
readonly package?: (typeof PACKAGES)[number];
|
||||
/**
|
||||
* The initial documentation class, function, interface etc.
|
||||
*
|
||||
* @example `'Client'`
|
||||
*/
|
||||
readonly parent?: string;
|
||||
/**
|
||||
* Whether to reference a static property.
|
||||
*
|
||||
* @remarks
|
||||
* This should only be used for the https://discord.js.org domain
|
||||
* as static properties are not identified in the URL.
|
||||
*/
|
||||
readonly static?: boolean;
|
||||
/**
|
||||
* The symbol belonging to the parent.
|
||||
*
|
||||
* @example '`login'`
|
||||
*/
|
||||
readonly symbol?: string;
|
||||
/**
|
||||
* The type of the {@link DocsLinkOptions.parent}.
|
||||
*
|
||||
* @example `'class'`
|
||||
* @example `'Function'`
|
||||
*/
|
||||
readonly type?: string;
|
||||
}
|
||||
|
||||
export function DocsLink({
|
||||
package: docs = PACKAGES[0],
|
||||
type,
|
||||
parent,
|
||||
symbol,
|
||||
brackets,
|
||||
static: staticReference,
|
||||
children,
|
||||
}: PropsWithChildren<DocsLinkOptions>) {
|
||||
// In the case of no type and no parent, this will default to the entry point of the respective documentation.
|
||||
let url = docs === PACKAGES[0] ? `${BASE_URL_LEGACY}/${VERSION}/general/welcome` : `${BASE_URL}/${docs}/stable`;
|
||||
let text = `${docs === PACKAGES[0] ? '' : '@discordjs/'}${docs}`;
|
||||
|
||||
// If there is a type and parent, we need to do some parsing.
|
||||
if (type && parent) {
|
||||
const bracketText = brackets || type?.toUpperCase() === 'FUNCTION' ? '()' : '';
|
||||
|
||||
// Legacy discord.js documentation parsing.
|
||||
if (docs === PACKAGES[0]) {
|
||||
url = `${BASE_URL_LEGACY}/${VERSION}/${type}/${parent}`;
|
||||
if (symbol) url += `?scrollTo=${symbol}`;
|
||||
|
||||
text = `${parent}${symbol ? (symbol.startsWith('s-') ? '.' : '#') : ''}${
|
||||
// eslint-disable-next-line prefer-named-capture-group
|
||||
symbol ? `${symbol.replace(/(e|s)-/, '')}` : ''
|
||||
}${bracketText}`;
|
||||
} else {
|
||||
url += `/${parent}:${type}`;
|
||||
if (symbol) url += `#${symbol}`;
|
||||
text = `${parent}${symbol ? `${staticReference ? '.' : '#'}${symbol}` : ''}${bracketText}`;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<a className="inline-flex flex-row place-items-center gap-1" href={url} rel="noopener noreferrer" target="_blank">
|
||||
{children ?? text}
|
||||
<FiExternalLink size={18} />
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
import Image from 'next/image';
|
||||
import vercelLogo from '~/assets/powered-by-vercel.svg';
|
||||
import workersLogo from '~/assets/powered-by-workers.png';
|
||||
|
||||
export default function Footer() {
|
||||
return (
|
||||
<footer className="md:pl-12 md:pr-12">
|
||||
<div className="flex flex-col flex-wrap place-content-center gap-6 pt-12 sm:flex-row md:gap-12">
|
||||
<div className="flex flex-wrap place-content-center place-items-center gap-4">
|
||||
<a
|
||||
className="rounded outline-none focus:ring focus:ring-width-2 focus:ring-blurple"
|
||||
href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"
|
||||
rel="external noopener noreferrer"
|
||||
target="_blank"
|
||||
title="Vercel"
|
||||
>
|
||||
<Image
|
||||
alt="Vercel"
|
||||
blurDataURL="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAABLCAQAAAA1k5H2AAAAi0lEQVR42u3SMQEAAAgDoC251a3gL2SgmfBYBRAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARCAgwWEOSWBnYbKggAAAABJRU5ErkJggg=="
|
||||
height={44}
|
||||
placeholder="blur"
|
||||
src={vercelLogo}
|
||||
width={212}
|
||||
/>
|
||||
</a>
|
||||
<a
|
||||
className="rounded outline-none focus:ring focus:ring-width-2 focus:ring-blurple"
|
||||
href="https://www.cloudflare.com"
|
||||
rel="external noopener noreferrer"
|
||||
target="_blank"
|
||||
title="Cloudflare Workers"
|
||||
>
|
||||
<Image
|
||||
alt="Cloudflare"
|
||||
blurDataURL="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAABLCAQAAAA1k5H2AAAAi0lEQVR42u3SMQEAAAgDoC251a3gL2SgmfBYBRAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARAAARCAgwWEOSWBnYbKggAAAABJRU5ErkJggg=="
|
||||
height={44}
|
||||
placeholder="blur"
|
||||
priority
|
||||
src={workersLogo}
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
<div className="flex flex-col place-self-center gap-6 sm:flex-row md:gap-12">
|
||||
<div className="max-w-max flex flex-col gap-2">
|
||||
<div className="text-lg font-semibold">Community</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<a
|
||||
className="rounded outline-none focus:ring focus:ring-width-2 focus:ring-blurple"
|
||||
href="https://discord.gg/djs"
|
||||
rel="external noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
Discord
|
||||
</a>
|
||||
<a
|
||||
className="rounded outline-none focus:ring focus:ring-width-2 focus:ring-blurple"
|
||||
href="https://github.com/discordjs/discord.js/discussions"
|
||||
rel="external noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
GitHub discussions
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div className="max-w-max flex flex-col gap-2">
|
||||
<div className="text-lg font-semibold">Project</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<a
|
||||
className="rounded outline-none focus:ring focus:ring-width-2 focus:ring-blurple"
|
||||
href="https://github.com/discordjs/discord.js"
|
||||
rel="external noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
discord.js
|
||||
</a>
|
||||
<a
|
||||
className="rounded outline-none focus:ring focus:ring-width-2 focus:ring-blurple"
|
||||
href="https://discord.js.org/docs"
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
discord.js documentation
|
||||
</a>
|
||||
<a
|
||||
className="rounded outline-none focus:ring focus:ring-width-2 focus:ring-blurple"
|
||||
href="https://discord-api-types.dev"
|
||||
rel="external noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
discord-api-types
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import type { HTMLAttributes, PropsWithChildren } from 'react';
|
||||
|
||||
export function H1({ children, className, ...props }: PropsWithChildren<HTMLAttributes<HTMLHeadingElement>>) {
|
||||
return (
|
||||
<h1 className={`group ${className}`} {...props}>
|
||||
{children}
|
||||
</h1>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import type { HTMLAttributes, PropsWithChildren } from 'react';
|
||||
|
||||
export function H2({ children, className, ...props }: PropsWithChildren<HTMLAttributes<HTMLHeadingElement>>) {
|
||||
return (
|
||||
<h2 className={`group ${className}`} {...props}>
|
||||
{children}
|
||||
</h2>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import type { HTMLAttributes, PropsWithChildren } from 'react';
|
||||
|
||||
export function H3({ children, className, ...props }: PropsWithChildren<HTMLAttributes<HTMLHeadingElement>>) {
|
||||
return (
|
||||
<h3 className={`group ${className}`} {...props}>
|
||||
{children}
|
||||
</h3>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
import type { HTMLAttributes, PropsWithChildren } from 'react';
|
||||
|
||||
export function H4({ children, className, ...props }: PropsWithChildren<HTMLAttributes<HTMLHeadingElement>>) {
|
||||
return (
|
||||
<h4 className={`group ${className}`} {...props}>
|
||||
{children}
|
||||
</h4>
|
||||
);
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { VscGithubInverted } from '@react-icons/all-files/vsc/VscGithubInverted';
|
||||
import { VscMenu } from '@react-icons/all-files/vsc/VscMenu';
|
||||
import { Button } from 'ariakit/button';
|
||||
import type { Route } from 'next';
|
||||
import dynamic from 'next/dynamic';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { Fragment, useMemo } from 'react';
|
||||
import { useNav } from '~/contexts/nav';
|
||||
|
||||
const ThemeSwitcher = dynamic(async () => import('./ThemeSwitcher'));
|
||||
|
||||
export default function Header() {
|
||||
const pathname = usePathname();
|
||||
const { setOpened } = useNav();
|
||||
|
||||
const pathElements = useMemo(
|
||||
() =>
|
||||
pathname
|
||||
.split('/')
|
||||
.slice(1)
|
||||
.map((path, idx, original) => (
|
||||
<Link
|
||||
className="rounded outline-none hover:underline focus:ring focus:ring-width-2 focus:ring-blurple"
|
||||
href={`/${original.slice(0, idx + 1).join('/')}` as Route}
|
||||
key={`${path}-${idx}`}
|
||||
>
|
||||
{path}
|
||||
</Link>
|
||||
)),
|
||||
[pathname],
|
||||
);
|
||||
|
||||
const breadcrumbs = useMemo(
|
||||
() =>
|
||||
pathElements.flatMap((el, idx, array) => {
|
||||
if (idx === 0) {
|
||||
return (
|
||||
<Fragment key={`${el.key}-${idx}`}>
|
||||
<div className="mx-2">/</div>
|
||||
<div>{el}</div>
|
||||
<div className="mx-2">/</div>
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
if (idx !== array.length - 1) {
|
||||
return (
|
||||
<Fragment key={`${el.key}-${idx}`}>
|
||||
<div>{el}</div>
|
||||
<div className="mx-2">/</div>
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
return <div key={`${el.key}-${idx}`}>{el}</div>;
|
||||
}),
|
||||
[pathElements],
|
||||
);
|
||||
|
||||
return (
|
||||
<header className="sticky top-4 z-20 border border-light-900 rounded-md bg-white/75 shadow backdrop-blur-md dark:border-dark-100 dark:bg-dark-600/75">
|
||||
<div className="block h-16 px-6">
|
||||
<div className="h-full flex flex-row place-content-between place-items-center gap-8">
|
||||
<Button
|
||||
aria-label="Menu"
|
||||
className="h-6 w-6 flex flex-row transform-gpu cursor-pointer select-none appearance-none place-items-center border-0 rounded bg-transparent p-0 text-sm font-semibold leading-none no-underline outline-none lg:hidden active:translate-y-px focus:ring focus:ring-width-2 focus:ring-blurple"
|
||||
onClick={() => setOpened((open) => !open)}
|
||||
>
|
||||
<VscMenu size={24} />
|
||||
</Button>
|
||||
<div className="hidden lg:flex lg:grow lg:flex-row lg:overflow-hidden">{breadcrumbs}</div>
|
||||
<div className="flex flex-row place-items-center gap-4">
|
||||
<Button
|
||||
aria-label="GitHub"
|
||||
as="a"
|
||||
className="h-6 w-6 flex flex-row transform-gpu cursor-pointer select-none appearance-none place-items-center border-0 rounded rounded-full bg-transparent p-0 text-sm font-semibold leading-none no-underline outline-none active:translate-y-px focus:ring focus:ring-width-2 focus:ring-blurple"
|
||||
href="https://github.com/discordjs/discord.js"
|
||||
rel="external noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
<VscGithubInverted size={24} />
|
||||
</Button>
|
||||
<ThemeSwitcher />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { Alert, Section, DiscordMessages, DiscordMessage, DiscordMessageEmbed } from '@discordjs/ui';
|
||||
import { useMDXComponent } from 'next-contentlayer/hooks';
|
||||
import { DocsLink } from '~/components/DocsLink';
|
||||
import { ResultingCode } from '~/components/ResultingCode';
|
||||
import { DiscordAPITypesLink } from './DiscordAPITypesLink';
|
||||
import { H1 } from './H1';
|
||||
import { H2 } from './H2';
|
||||
import { H3 } from './H3';
|
||||
import { H4 } from './H4';
|
||||
|
||||
export function Mdx({ code }: { readonly code: string }) {
|
||||
const Component = useMDXComponent(code);
|
||||
|
||||
return (
|
||||
<Component
|
||||
components={{
|
||||
Alert,
|
||||
Section,
|
||||
DiscordMessages,
|
||||
DiscordMessage,
|
||||
DiscordMessageEmbed,
|
||||
DiscordAPITypesLink,
|
||||
DocsLink,
|
||||
ResultingCode,
|
||||
h1: H1,
|
||||
h2: H2,
|
||||
h3: H3,
|
||||
h4: H4,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { Scrollbars } from 'react-custom-scrollbars-2';
|
||||
import { useNav } from '~/contexts/nav';
|
||||
import { Sidebar } from './Sidebar';
|
||||
|
||||
export function Nav() {
|
||||
const { opened } = useNav();
|
||||
|
||||
return (
|
||||
<nav
|
||||
className={`dark:bg-dark-600/75 dark:border-dark-100 border-light-900 top-22 fixed bottom-4 left-4 right-4 z-20 mx-auto max-w-5xl rounded-md border bg-white/75 shadow backdrop-blur-md ${
|
||||
opened ? 'block' : 'hidden'
|
||||
} lg:min-w-xs lg:sticky lg:block lg:h-full lg:w-full lg:max-w-xs`}
|
||||
>
|
||||
<Scrollbars
|
||||
autoHide
|
||||
className="[&>div]:overscroll-none"
|
||||
hideTracksWhenNotNeeded
|
||||
renderThumbVertical={(props) => <div {...props} className="z-30 rounded bg-light-900 dark:bg-dark-100" />}
|
||||
renderTrackVertical={(props) => (
|
||||
<div {...props} className="absolute bottom-0.5 right-0.5 top-0.5 z-30 w-1.5 rounded" />
|
||||
)}
|
||||
universal
|
||||
>
|
||||
<div className="flex flex-col gap-4 p-3">
|
||||
<Sidebar />
|
||||
</div>
|
||||
</Scrollbars>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { Scrollbars } from 'react-custom-scrollbars-2';
|
||||
|
||||
const LINK_HEIGHT = 30;
|
||||
const INDICATOR_SIZE = 10;
|
||||
const INDICATOR_OFFSET = (LINK_HEIGHT - INDICATOR_SIZE) / 2;
|
||||
|
||||
export function Outline({ headings }: { readonly headings: any[] }) {
|
||||
// eslint-disable-next-line react/hook-use-state
|
||||
const [active /* setActive */] = useState(0);
|
||||
|
||||
const headingItems = useMemo(
|
||||
() =>
|
||||
headings.map((heading, idx) => (
|
||||
<a
|
||||
className={`dark:border-dark-100 border-light-800 pl-6.5 focus:ring-width-2 focus:ring-blurple ml-[10px] border-l p-[5px] text-sm outline-none focus:rounded focus:border-0 focus:ring ${
|
||||
idx === active
|
||||
? 'bg-blurple text-white'
|
||||
: 'dark:hover:bg-dark-200 dark:active:bg-dark-100 hover:bg-light-700 active:bg-light-800'
|
||||
}`}
|
||||
href={`#${heading.slug}`}
|
||||
key={heading.slug}
|
||||
style={{ paddingLeft: `${heading.depth * 14}px` }}
|
||||
title={heading.text}
|
||||
>
|
||||
<span className="line-clamp-1">{heading.text}</span>
|
||||
</a>
|
||||
)),
|
||||
[headings, active],
|
||||
);
|
||||
|
||||
// useEffect(() => {
|
||||
// const idx = headings.findIndex((heading) => heading.slug === state.hash?.slice(1));
|
||||
// if (idx >= 0) {
|
||||
// setActive(idx);
|
||||
// }
|
||||
// }, [state, headings]);
|
||||
|
||||
return (
|
||||
<Scrollbars
|
||||
autoHide
|
||||
hideTracksWhenNotNeeded
|
||||
renderThumbVertical={(props) => <div {...props} className="z-30 rounded bg-light-900 dark:bg-dark-100" />}
|
||||
renderTrackVertical={(props) => (
|
||||
<div {...props} className="absolute bottom-0.5 right-0.5 top-0.5 z-30 w-1.5 rounded" />
|
||||
)}
|
||||
universal
|
||||
>
|
||||
<div className="flex flex-col break-all p-3 pb-8">
|
||||
<div className="ml-2 mt-4 flex flex-row gap-2">
|
||||
{/* <VscListSelection size={25} /> */}
|
||||
<span className="font-semibold">Contents</span>
|
||||
</div>
|
||||
<div className="ml-2 mt-4 flex flex-col gap-2">
|
||||
<div className="relative flex flex-col">
|
||||
<div
|
||||
className="absolute h-[10px] w-[10px] border-2 border-black rounded-full bg-blurple dark:border-white"
|
||||
style={{
|
||||
left: INDICATOR_SIZE / 2 + 0.5,
|
||||
transform: `translateY(${active * LINK_HEIGHT + INDICATOR_OFFSET}px)`,
|
||||
}}
|
||||
/>
|
||||
{headingItems}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Scrollbars>
|
||||
);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
export function PageButton({
|
||||
url,
|
||||
title,
|
||||
direction,
|
||||
}: {
|
||||
readonly direction: 'next' | 'prev';
|
||||
readonly title: string;
|
||||
readonly url: string;
|
||||
}) {
|
||||
return (
|
||||
<a
|
||||
className="flex flex-row flex-col transform-gpu cursor-pointer select-none appearance-none place-items-center gap-2 rounded bg-light-600 px-4 py-3 leading-none no-underline outline-none active:translate-y-px active:bg-light-800 dark:bg-dark-600 hover:bg-light-700 focus:ring focus:ring-width-2 focus:ring-blurple dark:active:bg-dark-400 dark:hover:bg-dark-500"
|
||||
href={url}
|
||||
>
|
||||
<h3 className="text-md font-semibold">{title}</h3>
|
||||
<p className={`${direction === 'next' ? 'ml-auto' : 'mr-auto'} text-sm text-gray-600 dark:text-gray-400`}>
|
||||
{direction === 'next' ? 'Next Page' : 'Previous Page'}
|
||||
</p>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
export function ResultingCode() {
|
||||
return null;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { Section as DJSSection, type SectionOptions } from '@discordjs/ui';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
|
||||
export function Section(options: PropsWithChildren<SectionOptions>) {
|
||||
return <DJSSection {...options} />;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import type { Route } from 'next';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { allContents } from 'contentlayer/generated';
|
||||
import { useNav } from '~/contexts/nav';
|
||||
import { Section } from './Section';
|
||||
|
||||
const items = allContents.map((content) => ({
|
||||
title: content.title,
|
||||
category: content.category,
|
||||
slug: content.slug,
|
||||
href: content.url,
|
||||
}));
|
||||
|
||||
function transformItemsByCategory(allContents: typeof items) {
|
||||
return allContents.reduce<Record<string, typeof items>>((accumulator: any, content) => {
|
||||
if (!accumulator[content.category]) {
|
||||
accumulator[content.category] = [];
|
||||
}
|
||||
|
||||
accumulator[content.category].push(content);
|
||||
return accumulator;
|
||||
}, {});
|
||||
}
|
||||
|
||||
const itemsByCategory = transformItemsByCategory(items);
|
||||
|
||||
export function Sidebar() {
|
||||
const pathname = usePathname();
|
||||
const { setOpened } = useNav();
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{Object.keys(itemsByCategory).map((category, idx) => (
|
||||
<Section
|
||||
buttonClassName="bg-light-600 hover:bg-light-700 active:bg-light-800 dark:bg-dark-400 dark:hover:bg-dark-300 dark:active:bg-dark-400 focus:ring-width-2 focus:ring-blurple rounded p-3 outline-none focus:ring z-10"
|
||||
key={`${category}-${idx}`}
|
||||
title={category}
|
||||
>
|
||||
{itemsByCategory[category]?.map((member, index) => (
|
||||
<Link
|
||||
className={`dark:border-dark-100 border-light-800 focus:ring-width-2 focus:ring-blurple ml-5 flex flex-col border-l first:mt-1 p-[5px] pl-6 outline-none focus:rounded focus:border-0 focus:ring ${
|
||||
decodeURIComponent(pathname ?? '') === member.href
|
||||
? 'bg-blurple text-white'
|
||||
: 'dark:hover:bg-dark-200 dark:active:bg-dark-100 hover:bg-light-700 active:bg-light-800'
|
||||
}`}
|
||||
href={member.href as Route}
|
||||
key={`${member.title}-${index}`}
|
||||
onClick={() => setOpened(false)}
|
||||
title={member.title}
|
||||
>
|
||||
<div className="flex flex-row place-items-center gap-2 lg:text-sm">
|
||||
<span className="truncate">{member.title}</span>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</Section>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import { VscColorMode } from '@react-icons/all-files/vsc/VscColorMode';
|
||||
import { Button } from 'ariakit/button';
|
||||
import { useTheme } from 'next-themes';
|
||||
|
||||
export default function ThemeSwitcher() {
|
||||
const { resolvedTheme, setTheme } = useTheme();
|
||||
const toggleTheme = () => setTheme(resolvedTheme === 'light' ? 'dark' : 'light');
|
||||
|
||||
return (
|
||||
<Button
|
||||
aria-label="Toggle theme"
|
||||
className="h-6 w-6 flex flex-row transform-gpu cursor-pointer select-none appearance-none place-items-center border-0 rounded rounded-full bg-transparent p-0 text-sm font-semibold leading-none no-underline outline-none active:translate-y-px focus:ring focus:ring-width-2 focus:ring-blurple"
|
||||
onClick={() => toggleTheme()}
|
||||
>
|
||||
<VscColorMode size={24} />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
---
|
||||
title: Introduction
|
||||
category: Home
|
||||
---
|
||||
|
||||
# Introduction
|
||||
|
||||
If you're reading this, it probably means you want to learn how to make a bot with discord.js. Awesome! You've come to the right place.
|
||||
This guide will teach you things such as:
|
||||
|
||||
- How to get a bot [up and running](../getting-started/starting-out) from scratch;
|
||||
- In-depth explanations regarding features and concepts of the API (e.g. [intents](../topics/intents), [threads](../topics/threads), [webhooks](../topics/webhooks));
|
||||
- And much more.
|
||||
|
||||
This guide will also cover subjects like common errors and how to solve them, keeping your code clean, setting up a proper development environment, etc.
|
||||
Sounds good? Great! Let's get started.
|
||||
|
||||
## Before you begin...
|
||||
|
||||
Alright, making a bot is cool and all, but there are some prerequisites to it. To create a bot with discord.js, you should have a fairly decent grasp of JavaScript itself.
|
||||
While you _can_ make a bot with very little JavaScript and programming knowledge, trying to do so without understanding the language first will only hinder you. You may get stuck on many uncomplicated issues, struggle with solutions to incredibly easy problems, and all-in-all end up frustrated. Sounds pretty annoying.
|
||||
|
||||
If you don't know JavaScript but would like to learn about it, here are a few links to help get you started:
|
||||
|
||||
- [Eloquent JavaScript, a free online book](http://eloquentjavascript.net)
|
||||
- [JavaScript.info, a modern javascript tutorial](https://javascript.info)
|
||||
- [Codecademy's interactive JavaScript course](https://codecademy.com/learn/introduction-to-javascript)
|
||||
- [Nodeschool, for both JavaScript and Node.js lessons](https://nodeschool.io)
|
||||
- [MDN's JavaScript guide and full documentation](https://developer.mozilla.org/docs/Web/JavaScript)
|
||||
- [Google, your best friend](https://google.com)
|
||||
|
||||
Take your pick, learn some JavaScript, and once you feel like you're confident enough to make a bot, come back and get started!
|
||||
@@ -1,49 +0,0 @@
|
||||
---
|
||||
title: What's new
|
||||
category: Home
|
||||
---
|
||||
|
||||
# What's new
|
||||
|
||||
<DiscordMessages rounded>
|
||||
<DiscordMessage
|
||||
interaction={{
|
||||
author: {
|
||||
avatar: '/assets/old-guide.png',
|
||||
username: 'discord.js',
|
||||
},
|
||||
command: '/upgrade',
|
||||
}}
|
||||
author={{
|
||||
avatar: '/assets/discordjs.png',
|
||||
bot: true,
|
||||
username: 'Guide Bot',
|
||||
time: 'Today at 21:00',
|
||||
}}
|
||||
>
|
||||
This website is new! We will no longer be updating the old guide website.
|
||||
</DiscordMessage>
|
||||
</DiscordMessages>
|
||||
|
||||
## Site
|
||||
|
||||
We have moved from VuePress to [Next.js](https://nextjs.org/)! The source can be found [here](https://github.com/discordjs/discord.js/tree/main/apps/guide).
|
||||
|
||||
## Pages
|
||||
|
||||
- Pages have been revamped to account for our new [create-discord-bot](https://github.com/discordjs/discord.js/tree/main/packages/create-discord-bot) command-line interface.
|
||||
- Popular topic are now simply "topics" that detail usage of a particular concept of the API.
|
||||
- Focus is primarily on discord.js, so irrelevant topics have been removed. It may be better to visit the documentation of the package you are using to learn how to use them.
|
||||
|
||||
<DiscordMessages rounded>
|
||||
<DiscordMessage
|
||||
author={{
|
||||
avatar: '/assets/discordjs.png',
|
||||
bot: true,
|
||||
username: 'Guide Bot',
|
||||
time: 'Today at 21:00',
|
||||
}}
|
||||
>
|
||||
Thank you to all of those that contributed to the development of discord.js and the guide!
|
||||
</DiscordMessage>
|
||||
</DiscordMessages>
|
||||
@@ -1,198 +0,0 @@
|
||||
---
|
||||
title: How to contribute
|
||||
category: Home
|
||||
---
|
||||
|
||||
# How to contribute
|
||||
|
||||
Since this guide is made specifically for the discord.js community, we want to be sure to provide the most relevant and up-to-date content. We will, of course, make additions to the current pages and add new ones as we see fit, but fulfilling requests is how we know we're providing content you all want the most.
|
||||
|
||||
Requests may be as simple as "add an example to the [frequently asked questions](../topics/frequently-asked-questions) page", or as elaborate as "add a page regarding [sharding](../topics/sharding)". We'll do our best to fulfill all requests, as long as they're reasonable.
|
||||
|
||||
To make a request, simply head over to [the repository's issue tracker](https://github.com/discordjs/discord.js/issues) and [create a new issue](https://github.com/discordjs/discord.js/issues/new)! Title it appropriately, and let us know exactly what you mean inside the issue description. Make sure that you've looked around the site before making a request; what you want to request might already exist!
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
Remember that you can always [fork the repository](https://github.com/discordjs/discord.js/fork) and [make a pull
|
||||
request](https://github.com/discordjs/discord.js/pulls) if you want to add anything to the guide yourself!
|
||||
</Alert>
|
||||
|
||||
We'll also get into some of the more advanced features this guide uses below. We recommended you have a look at the [source](https://github.com/discordjs/discord.js/blob/main/apps/guide/src/content/01-home/03-how-to-contribute.mdx) of this page to see exactly how they work.
|
||||
|
||||
## Components
|
||||
|
||||
Throughout the guide, you'll see some components from the _`@discordjs/ui`_ package:
|
||||
|
||||
- _`Alert`_
|
||||
- _`Section`_
|
||||
- _`DiscordMessages`_, _`DiscordMessage`_, and _`DiscordMessageEmbed`_
|
||||
|
||||
Check the source of this page to see them in action!
|
||||
|
||||
### Alert
|
||||
|
||||
This component may take a _`title`_ and a _`type`_ of _`'danger' | 'info' | 'success' | 'warning'`_.
|
||||
|
||||
This uses _`title="Alert" type="info"`_:
|
||||
|
||||
<Alert title="Alert" type="info">
|
||||
Use these appropriately!
|
||||
</Alert>
|
||||
|
||||
### Section
|
||||
|
||||
<Section title="Expand me!" padding defaultClosed background gutter>
|
||||
Well, hello there!
|
||||
|
||||
Whenever some text does not need to be in the main body, you can put it here.
|
||||
|
||||
- _`title`_: The title that'll appear.
|
||||
- _`padding`_: Adds padding.
|
||||
- _`dense`_: When _`padding`_ is specified, _`dense`_ could make it appear, well, dense.
|
||||
- _`defaultClosed`_ Whether the section is closed by default. This one was.
|
||||
- _`background`_ Adds background to the content.
|
||||
- _`gutter`_: This adds a very small appealing space between the expansion of the section and its content.
|
||||
|
||||
</Section>
|
||||
|
||||
### DiscordMessages, DiscordMessage, and DiscordMessageEmbed
|
||||
|
||||
<DiscordMessages>
|
||||
<DiscordMessage
|
||||
author={{
|
||||
avatar: '/assets/discordjs.png',
|
||||
bot: true,
|
||||
time: 'Today at 21:00',
|
||||
username: 'Guide Bot',
|
||||
}}
|
||||
>
|
||||
A _`DiscordMessage`_ must be within _`DiscordMessages`_.
|
||||
</DiscordMessage>
|
||||
<DiscordMessage
|
||||
author={{
|
||||
avatar: '/assets/discordjs.png',
|
||||
bot: true,
|
||||
time: 'Today at 21:01',
|
||||
username: 'Guide Bot',
|
||||
}}
|
||||
reply={{
|
||||
author: {
|
||||
avatar: '/assets/discordjs.png',
|
||||
bot: true,
|
||||
username: 'Guide Bot',
|
||||
},
|
||||
content: 'A _`DiscordMessage`_ must be within _`DiscordMessages`_.',
|
||||
}}
|
||||
time="21:02"
|
||||
>
|
||||
It's much better to see the source code of this page to replicate and learn!
|
||||
</DiscordMessage>
|
||||
<DiscordMessage
|
||||
author={{
|
||||
avatar: '/assets/discordjs.png',
|
||||
bot: true,
|
||||
time: 'Today at 21:02',
|
||||
username: 'Guide Bot',
|
||||
}}
|
||||
>
|
||||
This message depicts the use of embeds.
|
||||
<>
|
||||
<DiscordMessageEmbed
|
||||
author={{
|
||||
avatar: '/assets/discordjs.png',
|
||||
username: 'Guide Bot',
|
||||
}}
|
||||
footer={{ content: 'Sometimes, titles just have to be.' }}
|
||||
title={{ title: 'An amazing title' }}
|
||||
>
|
||||
This is a description. You can put a description here. It must be descriptive!
|
||||
</DiscordMessageEmbed>
|
||||
<DiscordMessageEmbed
|
||||
author={{
|
||||
avatar: '/assets/discordjs.png',
|
||||
username: 'Guide Bot',
|
||||
}}
|
||||
footer={{ content: "When one amazing title just wasn't enough." }}
|
||||
title={{ title: 'Another amazing title' }}
|
||||
>
|
||||
Multiple embeds!
|
||||
</DiscordMessageEmbed>
|
||||
</>
|
||||
</DiscordMessage>
|
||||
<DiscordMessage
|
||||
author={{
|
||||
avatar: '/assets/discordjs.png',
|
||||
bot: true,
|
||||
time: 'Today at 21:03',
|
||||
username: 'Guide Bot',
|
||||
}}
|
||||
interaction={{
|
||||
author: {
|
||||
avatar: '/assets/discordjs.png',
|
||||
bot: true,
|
||||
username: 'Guide Bot',
|
||||
},
|
||||
command: '/interaction',
|
||||
}}
|
||||
>
|
||||
Interactions are supported! I definitely used a command.
|
||||
</DiscordMessage>
|
||||
<DiscordMessage
|
||||
author={{
|
||||
avatar: '/assets/discordjs.png',
|
||||
bot: true,
|
||||
color: 'text-red-500',
|
||||
time: 'Today at 21:04',
|
||||
username: 'Guide Bot',
|
||||
}}
|
||||
reply={{
|
||||
author: {
|
||||
avatar: '/assets/snek-bot.jpeg',
|
||||
bot: true,
|
||||
verified: true,
|
||||
color: 'text-blue-500',
|
||||
username: 'Snek Bot',
|
||||
},
|
||||
content: 'You can also have verified bots, like me!',
|
||||
}}
|
||||
>
|
||||
Display colors are supported as well!
|
||||
</DiscordMessage>
|
||||
</DiscordMessages>
|
||||
|
||||
## Code blocks
|
||||
|
||||
We use [Code Hike](https://codehike.org). Here are some example code blocks, which should be easy to grasp and learn upon reading the source code of this page:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```ts
|
||||
const HELLO = 'hello' as const;
|
||||
console.log(HELLO);
|
||||
// "ts" is the language of the code block.
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```ts fileName
|
||||
const FILE_NAME = 'fileName' as const;
|
||||
if (FILE_NAME.includes(' ')) throw new Error('Spaces cannot be used in file names.');
|
||||
```
|
||||
|
||||
```ts anotherFileName
|
||||
const FILE_NAME_2 = 'anotherFileName' as const;
|
||||
// Putting code blocks together makes them appear in tabs, just like in your editor.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```ts requiredName
|
||||
const FILE_NAME_3 = 'requiredName' as const;
|
||||
if (!FILE_NAME) throw new Error('There must be a file name to use panels!');
|
||||
// The --- divider was used to create a panel.
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
For more information, be sure to check out the [documentation](https://codehike.org/docs/ch-code).
|
||||
@@ -1,64 +0,0 @@
|
||||
---
|
||||
title: Starting out
|
||||
category: Getting started
|
||||
---
|
||||
|
||||
# Starting out
|
||||
|
||||
Our [create-discord-bot](https://github.com/discordjs/discord.js/tree/main/packages/create-discord-bot) command-line interface sets up a basic Discord bot to help you get started on your journey.
|
||||
|
||||
## Creating your bot
|
||||
|
||||
To use discord.js, you'll need to install [Node.js](https://nodejs.org), [Deno](https://deno.com), or [Bun](https://bun.sh). discord.js v14 requires Node.js v16.11.0 or higher, but the long-term support (LTS) version is always recommended. For the purposes of this guide, we will be using Node.js.
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
To check if you already have Node.js installed, run _`node --version`_ in your terminal. If it outputs _`v16.11.0`_ or
|
||||
higher, then you're good to go!
|
||||
</Alert>
|
||||
|
||||
### Windows
|
||||
|
||||
- Download from the [Node.js website](https://nodejs.org).
|
||||
- Use [fnm](https://github.com/Schniz/fnm).
|
||||
- Use [Volta](https://volta.sh).
|
||||
|
||||
### macOS
|
||||
|
||||
- Download from the [Node.js website](https://nodejs.org/).
|
||||
- Use [fnm](https://github.com/Schniz/fnm).
|
||||
- Use [Homebrew](https://formulae.brew.sh/formula/node).
|
||||
- Use [nvm](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating).
|
||||
- Use [Volta](https://volta.sh).
|
||||
|
||||
### Linux
|
||||
|
||||
- Visit [this page](https://nodejs.org/en/download/package-manager) to determine how you should install Node.js.
|
||||
- Use [fnm](https://github.com/Schniz/fnm).
|
||||
- Use [nvm](https://github.com/nvm-sh/nvm).
|
||||
- Use [Volta](https://volta.sh).
|
||||
|
||||
After installing Node.js, you'll be able to create a new application from your desired package manager. If you're starting out fresh, installing Node.js will also install npm, a package manager for Node.js.
|
||||
|
||||
<CH.Code lineNumbers={false} showCopyButton={true}>
|
||||
|
||||
```sh npm
|
||||
npm create discord-bot
|
||||
```
|
||||
|
||||
```sh yarn
|
||||
yarn create discord-bot
|
||||
```
|
||||
|
||||
```sh pnpm
|
||||
pnpm create discord-bot
|
||||
```
|
||||
|
||||
```sh bun
|
||||
bun create discord-bot
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
You'll be asked the directory to create the application in, as well as whether TypeScript should be used. Dependencies will automatically be installed for you. After this, you've just got your startup Discord bot template _nearly_ ready!
|
||||
|
||||
In the next section, we will explain how to create an application to interact with Discord's API.
|
||||
@@ -1,64 +0,0 @@
|
||||
---
|
||||
title: Setting up an application
|
||||
category: Getting started
|
||||
---
|
||||
|
||||
# Setting up an application
|
||||
|
||||
You'll need to create an application on Discord's developer portal so your bot has a token to interact with Discord's API.
|
||||
|
||||
## Creating the application
|
||||
|
||||
Follow these steps:
|
||||
|
||||
1. Open the [Discord developer portal](https://discord.com/developers/applications). You'll need to be logged in.
|
||||
2. Click on the "New Application" button.
|
||||
3. Enter a name and confirm the pop-up window by clicking the "Create" button.
|
||||
- You'll need to agree to the [Developer Terms of Service](https://discord.com/developers/docs/policies-and-agreements/terms-of-service) and [Developer Policy](https://discord.com/developers/docs/policies-and-agreements/developer-policy).
|
||||
|
||||
You should see a page like this:
|
||||
|
||||

|
||||
|
||||
You can edit your application's name, description, and avatar here. Copy the application id and paste it in the .env file after _`APPLICATION_ID=`_.
|
||||
|
||||
Once you've saved your changes, move on by selecting the "Bot" tab in the left pane.
|
||||
|
||||
## Your bot's token
|
||||
|
||||
<Alert title="Important" type="danger">
|
||||
This section is critical, so pay close attention. It explains what your bot token is, as well as the security aspects
|
||||
of it.
|
||||
</Alert>
|
||||
|
||||
On the bot tab, you'll see a section like this:
|
||||
|
||||

|
||||
|
||||
In this panel, you can give your bot a snazzy avatar, set its username, and make it public or private. Your bot's token will be revealed when you press the "Reset Token" button and confirm. Once you've done this, copy it and paste it in the .env file after _`DISCORD_TOKEN=`_.
|
||||
|
||||
If you happen to lose this token at some point, you will need to come back to this page and reset it, which will reveal the new token, invalidating all old ones.
|
||||
|
||||
### Bot token explanation
|
||||
|
||||
A token is essentially your bot's password; it's what your bot uses to login to Discord. With that said, **it is vital that you do not ever share this token with anybody, purposely or accidentally**. If someone does manage to get a hold of your bot's token, they can use your bot as if it were theirs—this means they can perform malicious acts with it.
|
||||
|
||||
Tokens look like this: _`NzkyNzE1NDU0MTk2MDg4ODQy.X-hvzA.Ovy4MCQywSkoMRRclStW4xAYK7I`_ (don't worry, we immediately reset this token before even posting it here!). If it's any shorter and looks more like this: _`kxbsDRU5UfAaiO7ar9GFMHSlmTwYaIYn`_, you copied your client secret instead. Make sure to copy the token if you want your bot to work!
|
||||
|
||||
### Token leak scenario
|
||||
|
||||
Let's imagine that you have a bot on over 1,000 servers, and it took you many, many months of coding and patience to get it on that amount. Your bot's token gets leaked somewhere, and now someone else has it. That person can:
|
||||
|
||||
- Spam every server your bot is on;
|
||||
- DM spam as many users as possible;
|
||||
- Delete as many channels as possible;
|
||||
- Kick or ban as many server members as possible;
|
||||
- Make your bot leave all of the servers it has joined;
|
||||
|
||||
All that and much, much more. Sounds pretty terrible, right? So make sure to keep your bot's token as safe as possible!
|
||||
|
||||
<Alert title="Compromised tokens" type="danger">
|
||||
If your bot token has been compromised by committing it to a public repository, posting it in discord.js support etc.
|
||||
or otherwise see your bot's token in danger, return to this page and press "Reset Token". This will invalidate all old
|
||||
tokens belonging to your bot. Keep in mind that you will need to update your bot's token where you used it before.
|
||||
</Alert>
|
||||
@@ -1,48 +0,0 @@
|
||||
---
|
||||
title: Adding your bot to a server
|
||||
category: Getting started
|
||||
---
|
||||
|
||||
# Adding your bot to a server
|
||||
|
||||
After you [set up an application](./setting-up-an-application), you'll notice it's not in any servers yet. So, how does that work?
|
||||
|
||||
Before you're able to see your bot in a server, you will need to add it by using an invite link.
|
||||
|
||||
## Bot invite links
|
||||
|
||||
The basic version of one such link looks like this:
|
||||
|
||||
<CH.Code lineNumbers={false}>
|
||||
|
||||
```
|
||||
https://discord.com/api/oauth2/authorize?client_id=123456789012345678&permissions=0&scope=bot
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
The structure of the URL is quite simple:
|
||||
|
||||
- _`https://discord.com/api/oauth2/authorize`_ is Discord's standard structure for authorizing an OAuth2 application (such as your bot application) for entry to a Discord server.
|
||||
- _`client_id=...`_ is to specify _which_ application you want to authorize. You'll need to replace this part with your client's id to create a valid invite link.
|
||||
- _`permissions=...`_ describes the permissions that your bot will request to be granted by default upon joining the server you are adding it to.
|
||||
- _`scope=bot`_ specifies that you want to add this application as a Discord bot with the ability to create slash commands.
|
||||
|
||||
<Alert title="Warning" type="warning">
|
||||
If you get an error message saying "Bot requires a code grant", head over to your application's settings and disable
|
||||
the "Requires OAuth2 Code Grant" option. You shouldn't enable this option unless you know why you need to.
|
||||
</Alert>
|
||||
|
||||
## Creating and using your invite link
|
||||
|
||||
To create an invite link, head back to the [developer portal](https://discord.com/developers/applications), click on your bot application, and open the OAuth2 page.
|
||||
|
||||
In the sidebar, you'll find the URL generator. Select the _`bot`_ option. Once you select the _`bot`_ option, a list of permissions will appear, allowing you to configure the permissions your bot needs.
|
||||
|
||||
Grab the link via the "Copy" button and send it in a channel in Discord. Click on the link you just sent which should reveal this:
|
||||
|
||||

|
||||
|
||||
Choose the server you want to add the bot to and click "Authorize". Congratulations! You've successfully added your bot to your Discord server.
|
||||
|
||||
At this point, you should have a Discord bot you created with [create-discord-bot](https://github.com/discordjs/discord.js/tree/main/packages/create-discord-bot) with your .env file populated and your Discord bot in a server. You are now ready to do what you like.
|
||||
@@ -1,496 +0,0 @@
|
||||
---
|
||||
title: Frequently asked questions
|
||||
category: Topics
|
||||
---
|
||||
|
||||
# Frequently asked questions
|
||||
|
||||
## Legend
|
||||
|
||||
- _`client`_ is a placeholder for the <DocsLink type="class" parent="Client" /> object:
|
||||
_`const client = new Client({ intents: [GatewayIntentBits.Guilds] });`_.
|
||||
|
||||
- _`interaction`_ is a placeholder for the <DocsLink type="class" parent="BaseInteraction" />:
|
||||
_`client.on(Events.InteractionCreate, interaction => { ... });`_.
|
||||
|
||||
- _`guild`_ is a placeholder for the <DocsLink type="class" parent="Guild" /> object:
|
||||
_`interaction.guild`_ or _`client.guilds.cache.get('id')`_
|
||||
|
||||
- _`voiceChannel`_ is a placeholder for the <DocsLink type="class" parent="VoiceChannel" />:
|
||||
_`interaction.member.voice.channel`_.
|
||||
|
||||
For a more detailed explanation of the notations commonly used in this guide, the docs, and the support server, see [here](/additional-info/notation.md).
|
||||
|
||||
## Administrative
|
||||
|
||||
### How do I ban a user?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const user = interaction.options.getUser('target');
|
||||
await guild.members.ban(user);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I unban a user?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const user = interaction.options.getUser('target');
|
||||
await guild.members.unban(user);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
Discord validates and resolves user ids for users not on the server in user slash command options. To retrieve and use
|
||||
the full structure from the resulting interaction, you can use the{' '}
|
||||
<DocsLink type="class" parent="CommandInteractionOptionResolver" symbol="getUser" brackets /> method.
|
||||
</Alert>
|
||||
|
||||
### How do I kick a guild member?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const member = interaction.options.getMember('target');
|
||||
await member.kick();
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I timeout a guild member?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const member = interaction.options.getMember('target');
|
||||
await member.timeout(60_000); // Timeout for one minute
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
Timeout durations are measured by the millisecond. The maximum timeout duration you can set is 28 days. To remove a
|
||||
timeout set on a member, pass _`null`_ instead of a timeout duration.
|
||||
</Alert>
|
||||
|
||||
### How do I add a role to a guild member?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const role = interaction.options.getRole('role');
|
||||
const member = interaction.options.getMember('target');
|
||||
await member.roles.add(role);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I check if a guild member has a specific role?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const role = interaction.options.getRole('role');
|
||||
const member = interaction.options.getMember('target');
|
||||
|
||||
if (member.roles.cache.has(role.id) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I limit a command to a single user?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
if (interaction.user.id === 'id') {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Bot Configuration and Utility
|
||||
|
||||
### How do I set my bot's username?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
await client.user.setUsername('username');
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I set my bot's avatar?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
await client.user.setAvatar('URL or path');
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I set my playing status?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
client.user.setActivity('activity');
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I set my status to "Watching/Listening to/Competing in ..."?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
import { ActivityType } from 'discord.js';
|
||||
|
||||
client.user.setActivity('activity', { type: ActivityType.Watching });
|
||||
client.user.setActivity('activity', { type: ActivityType.Listening });
|
||||
client.user.setActivity('activity', { type: ActivityType.Competing });
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
If you would like to set your activity upon startup, you can use the{' '}
|
||||
<DocsLink type="typedef" parent="ClientOptions" /> object to set the appropriate
|
||||
<DocsLink type="typedef" parent="PresenceData" />.
|
||||
</Alert>
|
||||
|
||||
### How do I make my bot display online/idle/dnd/invisible?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
client.user.setStatus('online');
|
||||
client.user.setStatus('idle');
|
||||
client.user.setStatus('dnd');
|
||||
client.user.setStatus('invisible');
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I set both status and activity in one go?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
client.user.setPresence({ activities: [{ name: 'activity' }], status: 'idle' });
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Miscellaneous
|
||||
|
||||
### How do I send a message to a specific channel?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const channel = client.channels.cache.get('id');
|
||||
await channel.send('content');
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I create a post in a forum channel?
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
Currently, the only way to get tag ids is programmatically through{' '}
|
||||
<DocsLink type="class" parent="ForumChannel" symbol="availableTags" />.
|
||||
</Alert>
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const channel = client.channels.cache.get('id');
|
||||
|
||||
await channel.threads.create({
|
||||
name: 'Post name',
|
||||
message: { content: 'Message content' },
|
||||
appliedTags: ['tagId', 'anotherTagId'],
|
||||
});
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I DM a specific user?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
await client.users.send('id', 'content');
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
If you want to send a direct message to the user who sent the interaction, you can use _`interaction.user.send()`_.
|
||||
</Alert>
|
||||
|
||||
### How do I mention a specific user in a message?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const user = interaction.options.getUser('target');
|
||||
await interaction.reply(`Hi, ${user}.`);
|
||||
await interaction.followUp(`Hi, <@${user.id}>.`);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
Mentions in embeds may resolve correctly in embed titles, descriptions and field values but will never notify the
|
||||
user. Other areas do not support mentions at all.
|
||||
</Alert>
|
||||
|
||||
### How do I control which users and/or roles are mentioned in a message?
|
||||
|
||||
Controlling which mentions will send a ping is done via the _`allowedMentions`_ option, which replaces _`disableMentions`_.
|
||||
|
||||
This can be set as a default in <DocsLink type="typedef" parent="ClientOptions" />, and controlled per-message sent by your bot.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
new Client({ allowedMentions: { parse: ['users', 'roles'] } });
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
Even more control can be achieved by listing specific _`users`_ or _`roles`_ to be mentioned by id, e.g.:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
await channel.send({
|
||||
content: '<@123456789012345678> <@987654321098765432> <@&102938475665748392>',
|
||||
allowedMentions: { users: ['123456789012345678'], roles: ['102938475665748392'] },
|
||||
});
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I prompt the user for additional input?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
await interaction.reply('Please enter more input.');
|
||||
const filter = (m) => interaction.user.id === m.author.id;
|
||||
|
||||
try {
|
||||
const messages = await interaction.channel.awaitMessages({ filter, time: 60000, max: 1, errors: ['time'] });
|
||||
await interaction.followUp(`You've entered: ${messages.first().content}`);
|
||||
} catch {
|
||||
await interaction.followUp('You did not enter any input!');
|
||||
}
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
If you want to learn more about this syntax or other types of collectors, check out [this dedicated guide page for
|
||||
collectors](/popular-topics/collectors.md)!
|
||||
</Alert>
|
||||
|
||||
### How do I block a user from using my bot?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const blockedUsers = ['id1', 'id2'];
|
||||
|
||||
client.on(Events.InteractionCreate, (interaction) => {
|
||||
if (blockedUsers.includes(interaction.user.id)) return;
|
||||
});
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
You do not need to have a constant local variable like _`blockedUsers`_ above. If you have a database system that you
|
||||
use to store ids of blocked users, you can query the database instead.
|
||||
</Alert>
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
client.on(Events.InteractionCreate, async (interaction) => {
|
||||
const blockedUsers = await database.query('SELECT user_id FROM blocked_users;');
|
||||
if (blockedUsers.includes(interaction.user.id)) return;
|
||||
});
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
Note that this is just a showcase of how you could do such a check.
|
||||
|
||||
### How do I react to the message my bot sent?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const sentMessage = await interaction.channel.send('My message to react to.');
|
||||
// Unicode emoji
|
||||
await sentMessage.react('👍');
|
||||
|
||||
// Custom emoji
|
||||
await sentMessage.react('123456789012345678');
|
||||
await sentMessage.react('<emoji:123456789012345678>');
|
||||
await sentMessage.react('<a:emoji:123456789012345678>');
|
||||
await sentMessage.react('emoji:123456789012345678');
|
||||
await sentMessage.react('a:emoji:123456789012345678');
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
If you want to learn more about reactions, check out [this dedicated guide on
|
||||
reactions](/popular-topics/reactions.md)!
|
||||
</Alert>
|
||||
|
||||
### How do I restart my bot with a command?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
process.exit();
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Warning" type="warning">
|
||||
_`process.exit()`_ will only kill your Node process, but when using [PM2](https://pm2.keymetrics.io/), it will restart
|
||||
the process whenever it gets killed. You can read our guide on PM2 [here](/improving-dev-environment/pm2.md).
|
||||
</Alert>
|
||||
|
||||
### What is the difference between a User and a GuildMember?
|
||||
|
||||
A User represents a global Discord user, and a GuildMember represents a Discord user on a specific server. That means only GuildMembers can have permissions, roles, and nicknames, for example, because all of these things are server-bound information that could be different on each server that the user is in.
|
||||
|
||||
### How do I find all online members of a guild?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
// First use guild.members.fetch to make sure all members are cached
|
||||
const fetchedMembers = await guild.members.fetch({ withPresences: true });
|
||||
const totalOnline = fetchedMembers.filter((member) => member.presence?.status === 'online');
|
||||
// Now you have a collection with all online member objects in the totalOnline variable
|
||||
console.log(`There are currently ${totalOnline.size} members online in this guild!`);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Warning" type="warning">
|
||||
This only works correctly if you have the _`GuildPresences`_ intent enabled for your application and client. If you
|
||||
want to learn more about intents, check out [this dedicated guide on intents](/popular-topics/intents.md)!
|
||||
</Alert>
|
||||
|
||||
### How do I check which role was added/removed and for which member?
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
// Start by declaring a guildMemberUpdate listener
|
||||
// This code should be placed outside of any other listener callbacks to prevent listener nesting
|
||||
client.on(Events.GuildMemberUpdate, (oldMember, newMember) => {
|
||||
// If the role(s) are present on the old member object but no longer on the new one (i.e role(s) were removed)
|
||||
const removedRoles = oldMember.roles.cache.filter((role) => !newMember.roles.cache.has(role.id));
|
||||
|
||||
if (removedRoles.size > 0) {
|
||||
console.log(`The roles ${removedRoles.map((r) => r.name)} were removed from ${oldMember.displayName}.`);
|
||||
}
|
||||
|
||||
// If the role(s) are present on the new member object but are not on the old one (i.e role(s) were added)
|
||||
const addedRoles = newMember.roles.cache.filter((role) => !oldMember.roles.cache.has(role.id));
|
||||
|
||||
if (addedRoles.size > 0) {
|
||||
console.log(`The roles ${addedRoles.map((r) => r.name)} were added to ${oldMember.displayName}.`);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### How do I check the bot's ping?
|
||||
|
||||
There are two common measurements for bot pings. The first, **websocket heartbeat**, is the average interval of a regularly sent signal indicating the healthy operation of the websocket connection the library receives events over:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
await interaction.reply(`Websocket heartbeat: ${client.ws.ping}ms.`);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
If you're using [sharding](/sharding/), a specific shard's heartbeat can be found on the WebSocketShard instance,
|
||||
accessible at _`client.ws.shards.get(id).ping`_.
|
||||
</Alert>
|
||||
|
||||
The second, **Roundtrip Latency**, describes the amount of time a full API roundtrip (from the creation of the command message to the creation of the response message) takes. You then edit the response to the respective value to avoid needing to send yet another message:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const sent = await interaction.reply({ content: 'Pinging...', fetchReply: true });
|
||||
await interaction.editReply(`Roundtrip latency: ${sent.createdTimestamp - interaction.createdTimestamp}ms`);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### Why do some emojis behave weirdly?
|
||||
|
||||
If you've tried using [the usual method of retrieving unicode emojis](./reactions.md#unicode-emojis), you may have noticed that some characters don't provide the expected results. Here's a short snippet that'll help with that issue. You can toss this into a file of its own and use it anywhere you need! Alternatively feel free to simply copy-paste the characters from below:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js index.js
|
||||
import { emojiCharacters } from './emojiCharacters.js';
|
||||
|
||||
console.log(emojiCharacters.a); // 🇦
|
||||
console.log(emojiCharacters[10]); // 🔟
|
||||
console.log(emojiCharacters['!']); // ❗
|
||||
```
|
||||
|
||||
{/* prettier-ignore */}
|
||||
```js emojiCharacters.js
|
||||
export const emojiCharacters = {
|
||||
a: '🇦', b: '🇧', c: '🇨', d: '🇩',
|
||||
e: '🇪', f: '🇫', g: '🇬', h: '🇭',
|
||||
i: '🇮', j: '🇯', k: '🇰', l: '🇱',
|
||||
m: '🇲', n: '🇳', o: '🇴', p: '🇵',
|
||||
q: '🇶', r: '🇷', s: '🇸', t: '🇹',
|
||||
u: '🇺', v: '🇻', w: '🇼', x: '🇽',
|
||||
y: '🇾', z: '🇿', 0: '0️⃣', 1: '1️⃣',
|
||||
2: '2️⃣', 3: '3️⃣', 4: '4️⃣', 5: '5️⃣',
|
||||
6: '6️⃣', 7: '7️⃣', 8: '8️⃣', 9: '9️⃣',
|
||||
10: '🔟', '#': '#️⃣', '*': '*️⃣',
|
||||
'!': '❗', '?': '❓',
|
||||
};
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
You can use the <kbd>⌃ Control</kbd> <kbd>⌘ Command</kbd> <kbd>Space</kbd> keyboard shortcut to open up an emoji picker that can be used for quick, easy access to all the Unicode emojis available to you.
|
||||
|
||||
On Windows, the shortcut is <kbd>⊞</kbd> <kbd>.</kbd>.
|
||||
|
||||
</Alert>
|
||||
@@ -1,165 +0,0 @@
|
||||
---
|
||||
title: Audit logs
|
||||
category: Topics
|
||||
---
|
||||
|
||||
# Audit logs
|
||||
|
||||
## A Quick Background
|
||||
|
||||
Audit logs are an excellent moderation tool offered by Discord to know what happened in a server and usually by whom. Making use of audit logs requires the _`ViewAuditLog`_ permission. Audit logs may be fetched on a server, or they may be received via the gateway event <DocsLink type="class" parent="Client" symbol="e-guildAuditLogEntryCreate"/> which requires the _`GuildModeration`_ intent.
|
||||
|
||||
There are quite a few cases where you may use audit logs. This guide will limit itself to the most common use cases. Feel free to consult the [relevant Discord API page](https://discord.com/developers/docs/resources/audit-log) for more information.
|
||||
|
||||
Keep in mind that these examples explore a straightforward case and are by no means exhaustive. Their purpose is to teach you how audit logs work, and expansion of these examples is likely needed to suit your specific use case.
|
||||
|
||||
## Fetching Audit Logs
|
||||
|
||||
Let's start by glancing at the <DocsLink type="class" parent="Guild" symbol="fetchAuditLogs" brackets /> method and how to work with it. Like many discord.js methods, it returns a [Promise](../additional-info/understanding-async-await) containing the <DocsLink type="class" parent="GuildAuditLogs"/> object. This object has one property, _`entries`_, which holds a [Collection](../additional-info/collections) of <DocsLink type="class" parent="GuildAuditLogsEntry"/> objects, and consequently, the information you want to retrieve.
|
||||
|
||||
Here is the most basic fetch to look at some entries.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const fetchedLogs = await guild.fetchAuditLogs();
|
||||
const firstEntry = fetchedLogs.entries.first();
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
Simple, right? Now, let's look at utilizing its options:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
import { AuditLogEvent } from 'discord.js';
|
||||
|
||||
const fetchedLogs = await guild.fetchAuditLogs({
|
||||
type: AuditLogEvent.InviteCreate,
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
const firstEntry = fetchedLogs.entries.first();
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
This will return the first entry where an invite was created. You used _`limit: 1`_ here to specify only one entry.
|
||||
|
||||
## Receiving Audit Logs
|
||||
|
||||
Audit logs may be received via the gateway event <DocsLink type="class" parent="Client" symbol="e-guildAuditLogEntryCreate"/>.
|
||||
This is the best way to receive audit logs if you want to monitor them. As soon as an audit log entry is created,
|
||||
your application will receive an instance of this event. A common use case is to find out _who_ did the action that
|
||||
caused the audit log event to happen.
|
||||
|
||||
### Who deleted a message?
|
||||
|
||||
One of the most common use cases for audit logs is understanding who deleted a message in a Discord server. If a user deleted another user's message, you can find out who did that as soon as you receive the corresponding audit log event.
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
Messages deleted by their author or bots (excluding bulk deletes) do not generate audit log entries.
|
||||
</Alert>
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js JavaScript
|
||||
import { AuditLogEvent, Events } from 'discord.js';
|
||||
|
||||
client.on(Events.GuildAuditLogEntryCreate, async (auditLog) => {
|
||||
// Define your variables.
|
||||
// The extra information here will be the channel.
|
||||
const { action, extra: channel, executorId, targetId } = auditLog;
|
||||
|
||||
// Check only for deleted messages.
|
||||
if (action !== AuditLogEvent.MessageDelete) return;
|
||||
|
||||
// Ensure the executor is cached.
|
||||
const executor = await client.users.fetch(executorId);
|
||||
|
||||
// Ensure the author whose message was deleted is cached.
|
||||
const target = await client.users.fetch(targetId);
|
||||
|
||||
// Log the output.
|
||||
console.log(`A message by ${target.tag} was deleted by ${executor.tag} in ${channel}.`);
|
||||
});
|
||||
```
|
||||
|
||||
```ts TypeScript
|
||||
import { AuditLogEvent, Events } from 'discord.js';
|
||||
|
||||
client.on(Events.GuildAuditLogEntryCreate, async (auditLog) => {
|
||||
// Define your variables.
|
||||
// The extra information here will be the channel.
|
||||
const { action, extra: channel, executorId, targetId } = auditLog;
|
||||
|
||||
// Check only for deleted messages.
|
||||
if (action !== AuditLogEvent.MessageDelete) return;
|
||||
|
||||
// Ensure the executor is cached. The id definitely exists.
|
||||
const executor = await client.users.fetch(executorId!);
|
||||
|
||||
// Ensure the author whose message was deleted is cached. The id definitely exists.
|
||||
const target = await client.users.fetch(targetId!);
|
||||
|
||||
// Log the output.
|
||||
console.log(`A message by ${target.tag} was deleted by ${executor.tag} in ${channel}.`);
|
||||
});
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
With this, you now have a very simple logger telling you who deleted a message authored by another person.
|
||||
|
||||
### Who kicked a user?
|
||||
|
||||
This is very similar to the example above.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js JavaScript
|
||||
import { AuditLogEvent, Events } from 'discord.js';
|
||||
|
||||
client.on(Events.GuildAuditLogEntryCreate, async (auditLog) => {
|
||||
// Define your variables.
|
||||
const { action, executorId, targetId } = auditLog;
|
||||
|
||||
// Check only for kicked users.
|
||||
if (action !== AuditLogEvent.MemberKick) return;
|
||||
|
||||
// Ensure the executor is cached.
|
||||
const executor = await client.users.fetch(executorId);
|
||||
|
||||
// Ensure the kicked guild member is cached.
|
||||
const kickedUser = await client.users.fetch(targetId);
|
||||
|
||||
// Now you can log the output!
|
||||
console.log(`${kickedUser.tag} was kicked by ${executor.tag}.`);
|
||||
});
|
||||
```
|
||||
|
||||
```ts TypeScript
|
||||
import { AuditLogEvent, Events } from 'discord.js';
|
||||
|
||||
client.on(Events.GuildAuditLogEntryCreate, async (auditLog) => {
|
||||
// Define your variables.
|
||||
const { action, executorId, targetId } = auditLog;
|
||||
|
||||
// Check only for kicked users.
|
||||
if (action !== AuditLogEvent.MemberKick) return;
|
||||
|
||||
// Ensure the executor is cached. The id definitely exists.
|
||||
const executor = await client.users.fetch(executorId!);
|
||||
|
||||
// Ensure the kicked guild member is cached. The id definitely exists.
|
||||
const kickedUser = await client.users.fetch(targetId!);
|
||||
|
||||
// Now you can log the output!
|
||||
console.log(`${kickedUser.tag} was kicked by ${executor.tag}.`);
|
||||
});
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
If you want to check who banned a user, it's the same example as above except the _`action`_ should be <DiscordAPITypesLink type="enum" parent="AuditLogEvent" symbol="MemberBanAdd" />. You can check the rest of the possible actions on this page.
|
||||
@@ -1,223 +0,0 @@
|
||||
---
|
||||
title: Collectors
|
||||
category: Topics
|
||||
---
|
||||
|
||||
# Collectors
|
||||
|
||||
## Message collectors
|
||||
|
||||
{/* prettier-ignore */}
|
||||
<DocsLink type="class" parent="Collector">Collectors</DocsLink> are useful to enable your bot to obtain _additional_ input after the first command was sent. An example would be initiating a quiz, where the bot will "await" a correct response from somebody.
|
||||
|
||||
### Basic message collector
|
||||
|
||||
Let's take a look at a basic message collector:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const collectorFilter = (message) => message.content.includes('discord');
|
||||
const collector = interaction.channel.createMessageCollector({ filter: collectorFilter, time: 15_000 });
|
||||
|
||||
collector.on('collect', (message) => {
|
||||
console.log(`Collected ${message.content}`);
|
||||
});
|
||||
|
||||
collector.on('end', (collected) => {
|
||||
console.log(`Collected ${collected.size} messages`);
|
||||
});
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
You can provide a _`filter`_ key to the object parameter of <DocsLink type="class" parent="TextChannel" symbol="createMessageCollector" brackets />. The value to this key should be a function that returns a boolean value to indicate if this message should be collected or not. To check for multiple conditions in your filter you can connect them using [logical operators](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Expressions_and_Operators#logical_operators). If you don't provide a filter all messages in the channel the collector was started on will be collected.
|
||||
|
||||
Note that the above example uses [implicit return](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Functions/Arrow_functions#function_body) for the filter function and passes it to the options object using the [object property shorthand](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Object_initializer#property_definitions) notation.
|
||||
|
||||
If a message passes through the filter, it will trigger the <DocsLink type="class" parent="Collector" symbol="e-collect" /> event for the _`collector`_ you've created. This message is then passed into the event listener as _`collected`_ and the provided function is executed. In the above example, you simply log the message. Once the collector finishes collecting based on the provided end conditions the <DocsLink type="class" parent="Collector" symbol="e-end" /> event emits.
|
||||
|
||||
You can control when a collector ends by supplying additional option keys when creating a collector:
|
||||
|
||||
- _`time`_: Amount of time in milliseconds the collector should run for
|
||||
- _`max`_: Number of messages to successfully pass the filter
|
||||
- _`maxProcessed`_: Number of messages encountered (no matter the filter result)
|
||||
|
||||
The benefit of using an event-based collector over _`awaitMessages()`_ (its promise-based counterpart) is that you can do something directly after each message is collected, rather than just after the collector ended. You can also stop the collector manually by calling <DocsLink type="class" parent="Collector" symbol="stop" brackets />.
|
||||
|
||||
### Await messages
|
||||
|
||||
Using <DocsLink type="class" parent="TextChannel" symbol="awaitMessages" brackets /> can be easier if you understand [Promises](../additional-info/understanding-async-await), and it allows you to have cleaner code overall. It is essentially identical to <DocsLink type="class" parent="TextChannel" symbol="createMessageCollector" brackets />, except promisified. However, the drawback of using this method is that you cannot do things before the Promise is resolved or rejected, either by an error or completion. However, it should do for most purposes, such as awaiting the correct response in a quiz. Instead of taking their example, let's set up a basic quiz command using the _`.awaitMessages()`_ feature.
|
||||
|
||||
First, you'll need some questions and answers to choose from, so here's a basic set:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"question": "What color is the sky?",
|
||||
"answers": ["blue"]
|
||||
},
|
||||
{
|
||||
"question": "How many letters are there in the alphabet?",
|
||||
"answers": ["26", "twenty-six", "twenty six", "twentysix"]
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
The provided set allows for responder error with an array of answers permitted. Ideally, it would be best to place this in a JSON file, which you can call _`quiz.json`_ for simplicity.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
import quiz from './quiz.json' assert { type: 'json' };
|
||||
|
||||
// ...
|
||||
|
||||
const item = quiz[Math.floor(Math.random() * quiz.length)];
|
||||
|
||||
const collectorFilter = (response) => {
|
||||
return item.answers.some((answer) => answer.toLowerCase() === response.content.toLowerCase());
|
||||
};
|
||||
|
||||
await interaction.reply({ content: item.question });
|
||||
|
||||
try {
|
||||
const collected = await interaction.channel.awaitMessages({
|
||||
filter: collectorFilter,
|
||||
max: 1,
|
||||
time: 30_000,
|
||||
errors: ['time'],
|
||||
});
|
||||
|
||||
await interaction.followUp(`${collected.first().author} got the correct answer!`);
|
||||
} catch {
|
||||
await interaction.followUp('Looks like nobody got the answer this time.');
|
||||
}
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
If you don't understand how _`.some()`_ works, you can read about it in more detail
|
||||
[here](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/some).
|
||||
</Alert>
|
||||
|
||||
In this filter, you iterate through the answers to find what you want. You would like to ignore the case because simple typos can happen, so you convert each answer to its lowercase form and check if it's equal to the response in lowercase form as well. In the options section, you only want to allow one answer to pass through, hence the _`max: 1`_ setting.
|
||||
|
||||
The filter looks for messages that match one of the answers in the array of possible answers to pass through the collector. The _`max`_ option (the second parameter) specifies that only a maximum of one message can go through the filter successfully before the Promise successfully resolves. The _`errors`_ section specifies that time will cause it to error out, which will cause the Promise to reject if one correct answer is not received within the time limit of one minute. As you can see, there is no _`collect`_ event, so you are limited in that regard.
|
||||
|
||||
## Reaction collectors
|
||||
|
||||
### Basic reaction collector
|
||||
|
||||
These work quite similarly to message collectors, except that you apply them on a message rather than a channel. This example uses the <DocsLink type="class" parent="Message" symbol="createReactionCollector" brackets /> method. The filter will check for the 👍 emoji–in the default skin tone specifically, so be wary of that. It will also check that the person who reacted shares the same id as the author of the original message that the collector was assigned to.
|
||||
|
||||
```js
|
||||
const collectorFilter = (reaction, user) => {
|
||||
return reaction.emoji.name === '👍' && user.id === message.author.id;
|
||||
};
|
||||
|
||||
const collector = message.createReactionCollector({ filter: collectorFilter, time: 15_000 });
|
||||
|
||||
collector.on('collect', (reaction, user) => {
|
||||
console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);
|
||||
});
|
||||
|
||||
collector.on('end', (collected) => {
|
||||
console.log(`Collected ${collected.size} items`);
|
||||
});
|
||||
```
|
||||
|
||||
### Await reactions
|
||||
|
||||
<DocsLink type="class" parent="Message" symbol="awaitReactions" brackets /> works almost the same as a reaction collector,
|
||||
except it is Promise-based. The same differences apply as with channel collectors.
|
||||
|
||||
```js
|
||||
const collectorFilter = (reaction, user) => {
|
||||
return reaction.emoji.name === '👍' && user.id === message.author.id;
|
||||
};
|
||||
|
||||
try {
|
||||
const collected = await message.awaitReactions({ filter: collectorFilter, max: 1, time: 60_000, errors: ['time'] });
|
||||
console.log(collected.size);
|
||||
} catch (collected) {
|
||||
console.log(`After a minute, the user did not react.`);
|
||||
}
|
||||
```
|
||||
|
||||
## Interaction collectors
|
||||
|
||||
The third type of collector allows you to collect interactions; such as when users activate a slash command or click on a button in a message.
|
||||
|
||||
### Basic message component collector
|
||||
|
||||
Collecting interactions from message components works similarly to reaction collectors. In the following example, you will check that the interaction came from a button, and that the user clicking the button is the same user that initiated the command.
|
||||
|
||||
One important difference to note with interaction collectors is that Discord expects a response to _all_ interactions within 3 seconds - even ones that you don't want to collect. For this reason, you may wish to _`.deferUpdate()`_ all interactions in your filter, or not use a filter at all and handle this behavior in the _`collect`_ event.
|
||||
|
||||
```js
|
||||
import { ComponentType } from 'discord.js';
|
||||
|
||||
const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button, time: 15_000 });
|
||||
|
||||
collector.on('collect', (i) => {
|
||||
if (i.user.id === interaction.user.id) {
|
||||
await i.reply(`${i.user.id} clicked on the ${i.customId} button.`);
|
||||
} else {
|
||||
await i.reply({ content: `These buttons aren't for you!`, ephemeral: true });
|
||||
}
|
||||
});
|
||||
|
||||
collector.on('end', (collected) => {
|
||||
console.log(`Collected ${collected.size} interactions.`);
|
||||
});
|
||||
```
|
||||
|
||||
### Await message component
|
||||
|
||||
As before, this works similarly to the message component collector, except it is Promise-based.
|
||||
|
||||
Unlike other Promise-based collectors, this method will only ever collect one interaction that passes the filter. If no interactions are collected before the time runs out, the Promise will reject. This behavior aligns with Discord's requirement that actions should immediately receive a response. In this example, you will use _`.deferUpdate()`_ on all interactions in the filter.
|
||||
|
||||
```js
|
||||
import { ComponentType } from 'discord.js';
|
||||
|
||||
const collectorFilter = (i) => {
|
||||
i.deferUpdate();
|
||||
return i.user.id === interaction.user.id;
|
||||
};
|
||||
|
||||
try {
|
||||
const interaction = await message.awaitMessageComponent({
|
||||
filter: collectorFilter,
|
||||
componentType: ComponentType.StringSelect,
|
||||
time: 60_000,
|
||||
});
|
||||
|
||||
await interaction.editReply(`You selected ${interaction.values.join(', ')}!`);
|
||||
} catch (error) {
|
||||
console.log('No interactions were collected.');
|
||||
}
|
||||
```
|
||||
|
||||
### Await modal submit
|
||||
|
||||
If you want to wait for the submission of a modal within the context of another command or button execution, you may find the promisified collector <DocsLink type="class" parent="CommandInteraction" symbol="awaitModalSubmit" brackets /> useful.
|
||||
|
||||
As Discord does not inform you if the user dismisses the modal, supplying a maximum _`time`_ to wait for is crucial:
|
||||
|
||||
```js
|
||||
try {
|
||||
const interaction = await initialInteraction.awaitModalSubmit({ time: 60_000, filter });
|
||||
await interaction.editReply('Thank you for your submission!');
|
||||
} catch (error) {
|
||||
console.log('No modal submit interaction was collected');
|
||||
}
|
||||
```
|
||||
|
||||
For more information on working with modals, see the [modals section of this guide](../interactions/modals).
|
||||
@@ -1,95 +0,0 @@
|
||||
---
|
||||
title: Formatters
|
||||
category: Topics
|
||||
---
|
||||
|
||||
# Formatters
|
||||
|
||||
discord.js provides the <DocsLink package="formatters" /> package which contains a variety of utilities you can use when writing your Discord bot.
|
||||
|
||||
## Basic Markdown
|
||||
|
||||
These functions format strings into all the different markdown styles supported by Discord.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
import { bold, italic, strikethrough, underscore, spoiler, quote, blockQuote } from 'discord.js';
|
||||
|
||||
const string = 'Hello!';
|
||||
const boldString = bold(string);
|
||||
const italicString = italic(string);
|
||||
const strikethroughString = strikethrough(string);
|
||||
const underscoreString = underscore(string);
|
||||
const spoilerString = spoiler(string);
|
||||
const quoteString = quote(string);
|
||||
const blockquoteString = blockQuote(string);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Links
|
||||
|
||||
There are also two functions to format hyperlinks. _`hyperlink()`_ will format the URL into a masked markdown link, and _`hideLinkEmbed()`_ will wrap the URL in _`<>`_, preventing it from embedding.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
import { hyperlink, hideLinkEmbed } from 'discord.js';
|
||||
|
||||
const url = 'https://discord.js.org/';
|
||||
const link = hyperlink('discord.js', url);
|
||||
const hiddenEmbed = hideLinkEmbed(url);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Code blocks
|
||||
|
||||
You can use _`inlineCode()`_ and _`codeBlock()`_ to turn a string into an inline code block or a regular code block with or without syntax highlighting.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
import { inlineCode, codeBlock } from 'discord.js';
|
||||
|
||||
const jsString = 'const value = true;';
|
||||
const inline = inlineCode(jsString);
|
||||
const codeblock = codeBlock(jsString);
|
||||
const highlighted = codeBlock('js', jsString);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Timestamps
|
||||
|
||||
With _`time()`_, you can format Unix timestamps and dates into a Discord time string.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
import { time, TimestampStyles } from 'discord.js';
|
||||
|
||||
const date = new Date();
|
||||
const timeString = time(date);
|
||||
const relative = time(date, TimestampStyles.RelativeTime);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Mentions
|
||||
|
||||
_`userMention()`_, _`channelMention()`_, and _`roleMention()`_ all exist to format Snowflakes into mentions.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
import { channelMention, roleMention, userMention } from 'discord.js';
|
||||
|
||||
const id = '123456789012345678';
|
||||
const channel = channelMention(id);
|
||||
const role = roleMention(id);
|
||||
const user = userMention(id);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
@@ -1,68 +0,0 @@
|
||||
---
|
||||
title: Intents
|
||||
category: Topics
|
||||
---
|
||||
|
||||
# Intents
|
||||
|
||||
Intents are an important part of establishing a WebSocket connection, as they define behavior regarding gateway events and impact received data via the REST API.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
|
||||
const client = new Client({
|
||||
intents: [GatewayIntentBits.Guilds],
|
||||
});
|
||||
```
|
||||
|
||||
This is the most basic usage of intents for discord.js. By specifying _`GatewayIntentBits.Guilds`_, your bot will receive gateway events regarding guilds. This includes receiving initial information about guilds it is in at startup, such as role data.
|
||||
|
||||
You can find the full list of _`GatewayIntentBits`_ <DiscordAPITypesLink type="enum" parent="GatewayIntentBits">on the documentation</DiscordAPITypesLink> and an explanation of what each intent does [on Discord's API documentation](https://discord.com/developers/docs/topics/gateway#list-of-intents).
|
||||
|
||||
## Considerations
|
||||
|
||||
In discord.js, some intents require an extra bit of consideration.
|
||||
|
||||
### _`GatewayIntentBits.Guilds`_
|
||||
|
||||
discord.js relies heavily on caching in the library. We recommend you set at least the _`GatewayIntentBits.Guilds`_ intent to avoid these pitfalls.
|
||||
|
||||
### _`GatewayIntentBits.GuildMembers`_
|
||||
|
||||
Fetching members in a guild via <DocsLink type="class" parent="GuildMemberManager" symbol="fetch" brackets /> requests them over the gateway. As such, this intent is required and you may receive a timeout error if this intent is not specified.
|
||||
|
||||
<Alert title="Info" type="info">
|
||||
This is a privileged intent. Read on for more information.
|
||||
</Alert>
|
||||
|
||||
### _`GatewayIntentBits.DirectMessages`_
|
||||
|
||||
This intent is required to receive direct messages. In discord.js however, you **must** specify partials as well. See the partials topic on how this is done.
|
||||
|
||||
### _`GatewayIntentBits.MessageContent`_
|
||||
|
||||
Unlike other intents, this only populates user-generated fields. See [Discord's documentation](https://discord.com/developers/docs/topics/gateway#message-content-intent) on what exactly this intent unveils.
|
||||
|
||||
It is a common mistake to not see the message content in a message—this is usually because this intent is not specified.
|
||||
|
||||
<Alert title="Info" type="info">
|
||||
This is a privileged intent. Read on for more information.
|
||||
</Alert>
|
||||
|
||||
## Privileged intents
|
||||
|
||||
Some gateway events are considered privileged. Currently, these are:
|
||||
|
||||
- _`GatewayIntentBits.GuildPresences`_
|
||||
- _`GatewayIntentBits.GuildMembers`_
|
||||
- _`GatewayIntentBits.MessageContent`_
|
||||
|
||||
To use these intents, you will need to enable them in the developer portal. If your bot is in over 75 guilds, you will need to verify it and request usage of your desired intents.
|
||||
|
||||
Carefully think if you need these intents. They are opt-in so users across the platform can enjoy a higher level of privacy. Presences can expose some personal information, such as the games being played and overall online time. You might find that it isn't necessary for your bot to have this level of information about all guild members at all times.
|
||||
|
||||
### Disallowed intents
|
||||
|
||||
Should you receive an error stating you are using disallowed intents, please review your developer dashboard settings for all privileged intents you use. Check the Discord API documentation for up-to-date information.
|
||||
@@ -1,202 +0,0 @@
|
||||
---
|
||||
title: Threads
|
||||
category: Topics
|
||||
---
|
||||
|
||||
# Threads
|
||||
|
||||
Threads can be thought of as temporary sub-channels inside an existing channel to help better organize conversations in a busy channel.
|
||||
|
||||
## Thread related gateway events
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
You can use the <DocsLink type="class" parent="BaseChannel" symbol="isThread" brackets /> type guard to make sure a
|
||||
channel is a <DocsLink type="class" parent="ThreadChannel" />!
|
||||
</Alert>
|
||||
|
||||
Threads introduce a number of new gateway events, which are listed below:
|
||||
|
||||
- <DocsLink type="class" parent="Client" symbol="e-threadCreate" />: Emitted whenever a thread is created or when the
|
||||
client user is added to a thread.
|
||||
- <DocsLink type="class" parent="Client" symbol="e-threadDelete" />: Emitted whenever a thread is deleted.
|
||||
- <DocsLink type="class" parent="Client" symbol="e-threadUpdate" />: Emitted whenever a thread is updated (e.g. name
|
||||
change, archive state change, locked state change).
|
||||
- <DocsLink type="class" parent="Client" symbol="e-threadListSync" />: Emitted whenever the client user gains access to
|
||||
a text or announcement channel that contains threads.
|
||||
- <DocsLink type="class" parent="Client" symbol="e-threadMembersUpdate" />: Emitted whenever members are added or
|
||||
removed from a thread. Requires <code>GuildMembers</code> privileged intent.
|
||||
- <DocsLink type="class" parent="Client" symbol="e-threadMemberUpdate" />: Emitted whenever the client user's thread
|
||||
member is updated.
|
||||
|
||||
## Creating and deleting threads
|
||||
|
||||
Threads are created and deleted using the <DocsLink type="class" parent="GuildTextThreadManager" /> of a text or announcement channel.
|
||||
To create a thread, you call the <DocsLink type="class" parent="GuildTextThreadManager" symbol="create" brackets /> method:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
import { ThreadAutoArchiveDuration } from 'discord.js';
|
||||
|
||||
const thread = await channel.threads.create({
|
||||
name: 'food-talk',
|
||||
autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
|
||||
reason: 'Needed a separate thread for food',
|
||||
});
|
||||
|
||||
console.log(`Created thread: ${thread.name}`);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
They can also be created from an existing message with the <DocsLink type="class" parent="Message" symbol="startThread" brackets /> method, but will be "orphaned" if that message is deleted.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js focus=3[22:42]
|
||||
import { ThreadAutoArchiveDuration } from 'discord.js';
|
||||
|
||||
const thread = await message.startThread({
|
||||
name: 'food-talk',
|
||||
autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
|
||||
reason: 'Needed a separate thread for food',
|
||||
});
|
||||
|
||||
console.log(`Created thread: ${thread.name}`);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
The created thread and the message it originated from will share the same id. The type of thread created matches the parent channel's type.
|
||||
|
||||
To delete a thread, use the <DocsLink type="class" parent="ThreadChannel" symbol="delete" brackets /> method:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js focus=2
|
||||
const thread = channel.threads.cache.find((x) => x.name === 'food-talk');
|
||||
if (thread.manageable) await thread.delete();
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Joining and leaving threads
|
||||
|
||||
To subscribe your client to a thread, use the <DocsLink type="class" parent="ThreadChannel" symbol="join" brackets /> method:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js focus=2
|
||||
const thread = channel.threads.cache.find((x) => x.name === 'food-talk');
|
||||
if (thread.joinable) await thread.join();
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
And to leave one, use the <DocsLink type="class" parent="ThreadChannel" symbol="leave" brackets /> method:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js focus=2
|
||||
const thread = channel.threads.cache.find((x) => x.name === 'food-talk');
|
||||
await thread.leave();
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Archiving, unarchiving, and locking threads
|
||||
|
||||
A thread can be either active or archived. Changing a thread from archived to active is referred to as unarchiving the thread. Threads that have _`locked`_ set to _`true`_ can only be unarchived by a member with the _`ManageThreads`_ permission.
|
||||
|
||||
Threads are automatically archived after inactivity. "Activity" is defined as sending a message, unarchiving a thread, or changing the auto-archive time.
|
||||
|
||||
To archive or unarchive a thread, use the <DocsLink type="class" parent="ThreadChannel" symbol="setArchived" brackets /> method and pass in a boolean parameter:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js focus=2,3
|
||||
const thread = channel.threads.cache.find((x) => x.name === 'food-talk');
|
||||
await thread.setArchived(true); // Archived.
|
||||
await thread.setArchived(false); // Unarchived.
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
This same principle applies to locking and unlocking a thread via the <DocsLink type="class" parent="ThreadChannel" symbol="setLocked" brackets /> method:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js focus=2,3
|
||||
const thread = channel.threads.cache.find((x) => x.name === 'food-talk');
|
||||
await thread.setLocked(true); // Locked.
|
||||
await thread.setLocked(false); // Unlocked.
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Private threads
|
||||
|
||||
Public threads are viewable by everyone who can view the parent channel of the thread. Private threads, however, are only viewable to those who are invited or have the _`ManageThreads`_ permission. Private threads can only be created on text channels.
|
||||
|
||||
To create a private thread, use the <DocsLink type="class" parent="GuildTextThreadManager" symbol="create" brackets /> method and pass in _`ChannelType.PrivateThread`_ as the _`type`_:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js focus=1[10:21],6
|
||||
import { ChannelType, ThreadAutoArchiveDuration } from 'discord.js';
|
||||
|
||||
const thread = await channel.threads.create({
|
||||
name: 'mod-talk',
|
||||
autoArchiveDuration: ThreadAutoArchiveDuration.OneHour,
|
||||
type: ChannelType.PrivateThread,
|
||||
reason: 'Needed a separate thread for moderation',
|
||||
});
|
||||
|
||||
console.log(`Created thread: ${thread.name}`);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Adding and removing members
|
||||
|
||||
You can add members to a thread with the <DocsLink type="class" parent="ThreadMemberManager" symbol="add" brackets /> method. The thread must be unarchived and you must be able to send messages in it.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js focus=2
|
||||
const thread = channel.threads.cache.find((x) => x.name === 'food-talk');
|
||||
await thread.members.add('12345678901234567');
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
You can remove members from a thread with the <DocsLink type="class" parent="ThreadMemberManager" symbol="remove" brackets /> method. The thread must be unarchived and you must have the _`ManageThreads`_ permission unless the thread is private and you are the owner of it.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js focus=2
|
||||
const thread = channel.threads.cache.find((x) => x.name === 'food-talk');
|
||||
await thread.members.remove('12345678901234567');
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Sending messages to threads with webhooks
|
||||
|
||||
It is possible for a webhook built on the parent channel to send messages to the channel's threads. For the purpose of this example, it is assumed a single webhook already exists for that channel. If you wish to learn more about webhooks, see our [webhook guide](./webhooks).
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js focus=4:7
|
||||
const webhooks = await channel.fetchWebhooks();
|
||||
const webhook = webhooks.first();
|
||||
|
||||
await webhook.send({
|
||||
content: "Look ma! I'm in a thread!",
|
||||
threadId: '123456789012345678',
|
||||
});
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
And that's it! Now you know all there is to know on working with threads using discord.js!
|
||||
@@ -1,227 +0,0 @@
|
||||
---
|
||||
title: Webhooks
|
||||
category: Topics
|
||||
---
|
||||
|
||||
# Webhooks
|
||||
|
||||
Webhooks can send messages to a text channel without having to log in as a bot. They can also fetch, edit, and delete their own messages. There are a variety of methods in discord.js to interact with webhooks. In this section, you will learn how to create, fetch, edit, and use webhooks.
|
||||
|
||||
## What is a webhook
|
||||
|
||||
Webhooks are a utility used to send messages to text channels without needing a Discord application. Webhooks are useful for allowing something to send messages without requiring a Discord application. You can also directly edit or delete messages you sent through the webhook. There are two structures to make use of this functionality: <DocsLink type="class" parent="Webhook" /> and <DocsLink type="class" parent="WebhookClient" />. _`WebhookClient`_ is an extended version of a _`Webhook`_, which allows you to send messages through it without needing a bot client.
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
If you would like to read about using webhooks through the API without discord.js, you can read about them
|
||||
[here](https://discord.com/developers/docs/resources/webhook).
|
||||
</Alert>
|
||||
|
||||
## Detecting webhook messages
|
||||
|
||||
Bots receive webhook messages in a text channel as usual. You can detect if a webhook sent the message by checking if the _`Message.webhookId`_ is not _`null`_. In this example, we return if a webhook sent the message.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
if (message.webhookId) return;
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
If you would like to get the webhook object that sent the message, you can use <DocsLink type="class" parent="Message" symbol="fetchWebhook" brackets />.
|
||||
|
||||
## Fetching webhooks
|
||||
|
||||
<Alert title="Tip" type="info">
|
||||
Webhook fetching will always make use of collections and promises. If you do not understand either concept, revise
|
||||
them, and then come back to this section. You can read about collections [here](../additional-info/collections), and
|
||||
promises [here](../additional-info/understanding-async-await) and
|
||||
[here](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Using_promises).
|
||||
</Alert>
|
||||
|
||||
### Fetching all webhooks of a guild
|
||||
|
||||
If you would like to get all webhooks of a guild, you can use the <DocsLink type="class" parent="Guild" symbol="fetchWebhooks" brackets /> method. This will return a promise which will resolve into a collection of webhooks.
|
||||
|
||||
### Fetching webhooks of a channel
|
||||
|
||||
Webhooks belonging to a channel can be fetched using the <DocsLink type="class" parent="TextChannel" symbol="fetchWebhooks" brackets /> method. This will return a promise which will resolve into a collection of webhooks. A collection will be returned even if the channel contains a single webhook. If you are certain the channel contains a single webhook, you can use the <DocsLink package="collection" type="Class" parent="Collection" symbol="first" brackets /> method on the collection to get the webhook.
|
||||
|
||||
### Fetching a single webhook
|
||||
|
||||
#### Using client
|
||||
|
||||
You can fetch a specific webhook using its _`id`_ with the <DocsLink type="class" parent="Client" symbol="fetchWebhook" brackets /> method. You can obtain the webhook id by looking at its URL: the number after _`https://discord.com/api/webhooks/`_ is the _`id`_ and the part after that is the _`token`_.
|
||||
|
||||
#### Using the WebhookClient constructor
|
||||
|
||||
If you are not using a bot client, you can get a webhook by creating a new instance of _`WebhookClient`_ and passing the _`id`_ and _`token`_ into the constructor. These credentials do not require you to have a bot application, but it also offers limited information instead of fetching it using an authorized client.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const webhookClient = new WebhookClient({ id: 'id', token: 'token' });
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
You can also pass in just a _`url`_:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const webhookClient = new WebhookClient({ url: 'https://discord.com/api/webhooks/id/token' });
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Creating webhooks
|
||||
|
||||
### Creating webhooks through server settings
|
||||
|
||||
You can create webhooks directly through the Discord client. Go to Server Settings, and you will see an _`Integrations`_ tab.
|
||||
|
||||

|
||||
|
||||
If you already have created a webhook, the webhooks tab will look like this; you will need to click the _`View Webhooks`_ button.
|
||||
|
||||

|
||||
|
||||
Once you are there, click on the _`Create Webhook`_ / _`New Webhook`_ button; this will create a webhook. From here, you can edit the channel, the name, and the avatar. Copy the link, the first part is the id, and the second is the token.
|
||||
|
||||

|
||||
|
||||
### Creating webhooks with discord.js
|
||||
|
||||
Webhooks can be created with the <DocsLink type="class" parent="TextChannel" symbol="createWebhook" brackets /> method.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
channel
|
||||
.createWebhook({ name: 'Username', avatar: 'https://guide.discordjs.dev/assets/discordjs.png' })
|
||||
.then((webhook) => console.log(`Created webhook ${webhook}`))
|
||||
.catch(console.error);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Editing webhooks
|
||||
|
||||
You can edit Webhooks and WebhookClients to change their name, avatar, and channel using <DocsLink type="class" parent="Webhook" symbol="edit" brackets />.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
webhook
|
||||
.edit({ name: 'Username', avatar: 'https://guide.discordjs.dev/assets/discordjs.png', channel: '123456789012345678' })
|
||||
.then((webhook) => console.log(`Edited webhook ${webhook}`))
|
||||
.catch(console.error);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
## Using webhooks
|
||||
|
||||
Webhooks can send messages to text channels, as well as fetch, edit, and delete their own. These methods are the same for both _`Webhook`_ and _`WebhookClient`_.
|
||||
|
||||
### Sending messages
|
||||
|
||||
Webhooks, like bots, can send up to 10 embeds per message. They can also send attachments and normal content. The <DocsLink type="class" parent="Webhook" symbol="send" brackets /> method is very similar to the method used for sending a message to a text channel. Webhooks can also choose how the username and avatar will appear when they send the message.
|
||||
|
||||
Example using a _`WebhookClient`_:
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
import { EmbedBuilder, WebhookClient } from 'discord.js';
|
||||
import config from './config.json' assert { type: 'json' };
|
||||
const { webhookId, webhookToken } = config;
|
||||
|
||||
const webhookClient = new WebhookClient({ id: webhookId, token: webhookToken });
|
||||
const embed = new EmbedBuilder().setTitle('Some Title').setColor(0x00ffff);
|
||||
|
||||
await webhookClient.send({
|
||||
content: 'Webhook test',
|
||||
username: 'some-username',
|
||||
avatarURL: 'https://guide.discordjs.dev/assets/discordjs.png',
|
||||
embeds: [embed],
|
||||
});
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
Try to find a webhook your bot knows the token for. This makes sure your bot can execute the webhook later on.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
import { Client, EmbedBuilder, Events, GatewayIntentBits } from 'discord.js';
|
||||
import config from './config.json' assert { type: 'json' };
|
||||
const { token } = config;
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
const embed = new EmbedBuilder().setTitle('Some Title').setColor(0x00ffff);
|
||||
|
||||
client.once(Events.ClientReady, async () => {
|
||||
const channel = client.channels.cache.get('123456789012345678');
|
||||
|
||||
try {
|
||||
const webhooks = await channel.fetchWebhooks();
|
||||
const webhook = webhooks.find((wh) => wh.token);
|
||||
if (!webhook) return console.log('No webhook was found that I can use!');
|
||||
|
||||
await webhook.send({
|
||||
content: 'Webhook test',
|
||||
username: 'some-username',
|
||||
avatarURL: 'https://guide.discordjs.dev/assets/discordjs.png',
|
||||
embeds: [embed],
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error trying to send a message: ', error);
|
||||
}
|
||||
});
|
||||
|
||||
client.login(token);
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### Fetching messages
|
||||
|
||||
You can use <DocsLink type="class" parent="Webhook" symbol="fetchMessage" brackets /> to fetch messages previously sent by the Webhook.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const message = await webhookClient.fetchMessage('123456789012345678');
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### Editing messages
|
||||
|
||||
You can use <DocsLink type="class" parent="Webhook" symbol="editMessage" brackets /> to edit messages previously sent by the Webhook.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
const message = await webhook.editMessage('123456789012345678', {
|
||||
content: 'Edited!',
|
||||
embeds: [embed],
|
||||
});
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||
|
||||
### Deleting messages
|
||||
|
||||
You can use <DocsLink type="class" parent="Webhook" symbol="deleteMessage" brackets /> to delete messages previously sent by the webhook.
|
||||
|
||||
<CH.Code>
|
||||
|
||||
```js
|
||||
await webhookClient.deleteMessage('123456789012345678');
|
||||
```
|
||||
|
||||
</CH.Code>
|
||||