Skip to content

Commit 18c2dcc

Browse files
JiralitesdanialrazaalmostSoujikodiakhq[bot]
authored
feat: Utilise create-discord-bot (#10013)
* feat: utilise create-discord-bot * chore: hide line numbers * feat: add intents page * feat: add more Node.js variants * refactor: redo page a bit * fix: 👀 * chore: touch up introduction page * chore: touch up what's new * chore: touch up how to contribute * chore: remove enforced locale * chore: Fix typo Co-authored-by: Danial Raza <[email protected]> * chore: commit suggestions Co-authored-by: Souji <[email protected]> * chore: address improper capitalisation Co-authored-by: Souji <[email protected]> * refactor: remove `applications.commands` * refactor: remove unique comment * fix(intents): remove shard comment * docs(intents): add missing info --------- Co-authored-by: Danial Raza <[email protected]> Co-authored-by: Souji <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent adfd9cd commit 18c2dcc

30 files changed

+225
-1261
lines changed
142 KB
Loading
-13.3 KB
Binary file not shown.
-6.62 KB
Binary file not shown.

apps/guide/public/assets/bot-user.png

39.6 KB
Loading
225 KB
Loading

apps/guide/src/content/01-home/01-introduction.mdx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,12 @@ category: Home
88
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.
99
This guide will teach you things such as:
1010

11-
- How to get a bot [up and running](/preparations/) from scratch;
12-
- How to properly [create](/creating-your-bot/), [organize](/creating-your-bot/handling-command-interactions.md), and expand on your commands;
13-
- In-depth explanations and examples regarding popular topics (e.g. [reactions](/popular-topics/reactions.md), [embeds](/popular-topics/embeds.md), [canvas](/popular-topics/canvas.md));
14-
- Working with databases (e.g. [sequelize](/sequelize/) and [keyv](/keyv/));
15-
- Getting started with [sharding](/sharding/);
11+
- How to get a bot [up and running](../getting-started/starting-out) from scratch;
12+
- In-depth explanations regarding features and concepts of the API (e.g. [intents](../topics/intents), [threads](../topics/threads), [webhooks](../topics/webhooks));
1613
- And much more.
1714

1815
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.
19-
Sounds good? Great! Let's get started, then.
16+
Sounds good? Great! Let's get started.
2017

2118
## Before you begin...
2219

@@ -25,11 +22,11 @@ While you _can_ make a bot with very little JavaScript and programming knowledge
2522

2623
If you don't know JavaScript but would like to learn about it, here are a few links to help get you started:
2724

28-
- [Eloquent JavaScript, a free online book](http://eloquentjavascript.net/)
29-
- [JavaScript.info, a modern javascript tutorial](https://javascript.info/)
30-
- [Codecademy's interactive JavaScript course](https://www.codecademy.com/learn/introduction-to-javascript)
31-
- [Nodeschool, for both JavaScript and Node.js lessons](https://nodeschool.io/)
32-
- [MDN's JavaScript guide and full documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript)
25+
- [Eloquent JavaScript, a free online book](http://eloquentjavascript.net)
26+
- [JavaScript.info, a modern javascript tutorial](https://javascript.info)
27+
- [Codecademy's interactive JavaScript course](https://codecademy.com/learn/introduction-to-javascript)
28+
- [Nodeschool, for both JavaScript and Node.js lessons](https://nodeschool.io)
29+
- [MDN's JavaScript guide and full documentation](https://developer.mozilla.org/docs/Web/JavaScript)
3330
- [Google, your best friend](https://google.com)
3431

3532
Take your pick, learn some JavaScript, and once you feel like you're confident enough to make a bot, come back and get started!

apps/guide/src/content/01-home/02-whats-new.mdx

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ category: Home
2121
time: 'Today at 21:00',
2222
}}
2323
>
24-
discord.js v14 has released and the guide has been updated!
25-
<br />
26-
This includes additions and changes made in Discord, such as slash commands and message components.
24+
This website is new! We will no longer be updating the old guide website.
2725
</DiscordMessage>
2826
</DiscordMessages>
2927

@@ -33,25 +31,9 @@ We have moved from VuePress to [Next.js](https://nextjs.org/)! The source can be
3331

3432
## Pages
3533

36-
All content has been updated to use discord.js v14 syntax. The v13 version of the guide can be found at https://v13.discordjs.guide.
37-
38-
### New
39-
40-
- [Updating from v13 to v14](/additional-info/changes-in-v14.md): A list of the changes from discord.js v13 to v14
41-
- [Slash commands](/interactions/slash-commands.md): Registering, replying to slash commands and permissions
42-
- [Buttons](/interactions/buttons.md): Building, sending, and receiving buttons
43-
- [Select menus](/interactions/select-menus.md): Building, sending, and receiving select menus
44-
- [Threads](/popular-topics/threads.md): Creating and managing threads
45-
- [Builders](/popular-topics/builders.md): A collection of builders to use with your bot
46-
47-
### Updated
48-
49-
- Commando: Replaced with [Sapphire](https://sapphirejs.dev/docs/Guide/getting-started/getting-started-with-sapphire)
50-
- [Voice](/voice/): Rewritten to use the [_`@discordjs/voice`_](https://github.com/discordjs/discord.js/tree/main/packages/voice) package
51-
- [Command handling](/creating-your-bot/handling-command-interactions.md/): Updated to use slash commands
52-
- Obsolete sections removed
53-
- _`client.on('message')`_ snippets updated to _`client.on(Events.InteractionCreate)`_
54-
- [Message content became a privileged intent on August 31, 2022](https://support-dev.discord.com/hc/articles/4404772028055)
34+
- 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.
35+
- Popular topic are now simply "topics" that detail usage of a particular concept of the API.
36+
- 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.
5537

5638
<DiscordMessages rounded>
5739
<DiscordMessage

apps/guide/src/content/01-home/03-how-to-contribute.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ category: Home
77

88
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.
99

10-
Requests may be as simple as "add an example to the [frequently asked questions](/popular-topics/faq.html) page", or as elaborate as "add a page regarding [sharding](/sharding/)". We'll do our best to fulfill all requests, as long as they're reasonable.
10+
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.
1111

1212
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!
1313

14-
<Alert title="Tip" type="success">
14+
<Alert title="Tip" type="info">
1515
Remember that you can always [fork the repository](https://github.com/discordjs/discord.js/fork) and [make a pull
1616
request](https://github.com/discordjs/discord.js/pulls) if you want to add anything to the guide yourself!
1717
</Alert>
1818

19-
We'll also get into some of the more advanced features this guide does below.
19+
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.
2020

2121
## Components
2222

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Starting out
3+
category: Getting started
4+
---
5+
6+
# Starting out
7+
8+
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.
9+
10+
## Creating your bot
11+
12+
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.
13+
14+
<Alert title="Tip" type="info">
15+
To check if you already have Node.js installed, run _`node --version`_ in your terminal. If it outputs _`v16.11.0`_ or
16+
higher, then you're good to go!
17+
</Alert>
18+
19+
### Windows
20+
21+
- Download from the [Node.js website](https://nodejs.org).
22+
- Use [fnm](https://github.com/Schniz/fnm).
23+
- Use [Volta](https://volta.sh).
24+
25+
### macOS
26+
27+
- Download from the [Node.js website](https://nodejs.org/).
28+
- Use [fnm](https://github.com/Schniz/fnm).
29+
- Use [Homebrew](https://formulae.brew.sh/formula/node).
30+
- Use [nvm](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating).
31+
- Use [Volta](https://volta.sh).
32+
33+
### Linux
34+
35+
- Visit [this page](https://nodejs.org/en/download/package-manager) to determine how you should install Node.js.
36+
- Use [fnm](https://github.com/Schniz/fnm).
37+
- Use [nvm](https://github.com/nvm-sh/nvm).
38+
- Use [Volta](https://volta.sh).
39+
40+
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.
41+
42+
<CH.Code lineNumbers={false} showCopyButton={true}>
43+
44+
```sh npm
45+
npm create discord-bot
46+
```
47+
48+
```sh yarn
49+
yarn create discord-bot
50+
```
51+
52+
```sh pnpm
53+
pnpm create discord-bot
54+
```
55+
56+
```sh bun
57+
bun create discord-bot
58+
```
59+
60+
</CH.Code>
61+
62+
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!
63+
64+
In the next section, we will explain how to create an application to interact with Discord's API.
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
---
2-
title: Setting up a bot application
3-
category: Installations and preparations
2+
title: Setting up an application
3+
category: Getting started
44
---
55

6-
# Setting up a bot application
6+
# Setting up an application
77

8-
## Creating your bot
8+
You'll need to create an application on Discord's developer portal so your bot has a token to interact with Discord's API.
99

10-
Now that you've installed Node, discord.js, and hopefully a linter, you're almost ready to start coding! The next step you need to take is setting up an actual Discord bot application via Discord's website.
10+
## Creating the application
1111

12-
It's effortless to create one. The steps you need to take are as follows:
12+
Follow these steps:
1313

14-
1. Open the [Discord developer portal](https://discord.com/developers/applications) and log into your account.
14+
1. Open the [Discord developer portal](https://discord.com/developers/applications). You'll need to be logged in.
1515
2. Click on the "New Application" button.
1616
3. Enter a name and confirm the pop-up window by clicking the "Create" button.
17+
- 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).
1718

1819
You should see a page like this:
1920

2021
![Successfully created application](/assets/create-app.png)
2122

22-
You can edit your application's name, description, and avatar here. Once you've saved your changes, move on by selecting the "Bot" tab in the left pane.
23+
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=`_.
24+
25+
Once you've saved your changes, move on by selecting the "Bot" tab in the left pane.
2326

2427
## Your bot's token
2528

@@ -32,9 +35,11 @@ On the bot tab, you'll see a section like this:
3235

3336
![Bot application](/assets/bot-user.png)
3437

35-
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. When we ask you to paste your bot's token somewhere, this is the value that you need to put in. If you happen to lose your bot's token at some point, you need to come back to this page and reset your bot's token again which will reveal the new token, invalidating all old ones.
38+
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=`_.
39+
40+
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.
3641

37-
### What is a token, anyway?
42+
### Bot token explanation
3843

3944
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.
4045

@@ -52,8 +57,6 @@ Let's imagine that you have a bot on over 1,000 servers, and it took you many, m
5257

5358
All that and much, much more. Sounds pretty terrible, right? So make sure to keep your bot's token as safe as possible!
5459

55-
In the [configuration files](../creating-your-bot/configuration-files) page of the guide, we cover how to safely store your bot's token in a configuration file.
56-
5760
<Alert title="Compromised tokens" type="danger">
5861
If your bot token has been compromised by committing it to a public repository, posting it in discord.js support etc.
5962
or otherwise see your bot's token in danger, return to this page and press "Reset Token". This will invalidate all old
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Adding your bot to a server
3+
category: Getting started
4+
---
5+
6+
# Adding your bot to a server
7+
8+
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?
9+
10+
Before you're able to see your bot in a server, you will need to add it by using an invite link.
11+
12+
## Bot invite links
13+
14+
The basic version of one such link looks like this:
15+
16+
<CH.Code lineNumbers={false}>
17+
18+
```
19+
https://discord.com/api/oauth2/authorize?client_id=123456789012345678&permissions=0&scope=bot
20+
```
21+
22+
</CH.Code>
23+
24+
The structure of the URL is quite simple:
25+
26+
- _`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.
27+
- _`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.
28+
- _`permissions=...`_ describes the permissions that your bot will request to be granted by default upon joining the server you are adding it to.
29+
- _`scope=bot`_ specifies that you want to add this application as a Discord bot with the ability to create slash commands.
30+
31+
<Alert title="Warning" type="warning">
32+
If you get an error message saying "Bot requires a code grant", head over to your application's settings and disable
33+
the "Requires OAuth2 Code Grant" option. You shouldn't enable this option unless you know why you need to.
34+
</Alert>
35+
36+
## Creating and using your invite link
37+
38+
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.
39+
40+
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.
41+
42+
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:
43+
44+
![Bot Authorization page](/assets/bot-auth-page.png)
45+
46+
Choose the server you want to add the bot to and click "Authorize". Congratulations! You've successfully added your bot to your Discord server.
47+
48+
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.

apps/guide/src/content/02-installations-and-preparations/01-installing-node-discordjs.mdx

Lines changed: 0 additions & 110 deletions
This file was deleted.

apps/guide/src/content/02-installations-and-preparations/02-setting-up-a-linter.mdx

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)