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 <danialrazafb@gmail.com>

* chore: commit suggestions

Co-authored-by: Souji <timoqueezle@gmail.com>

* chore: address improper capitalisation

Co-authored-by: Souji <timoqueezle@gmail.com>

* refactor: remove `applications.commands`

* refactor: remove unique comment

* fix(intents): remove shard comment

* docs(intents): add missing info

---------

Co-authored-by: Danial Raza <danialrazafb@gmail.com>
Co-authored-by: Souji <timoqueezle@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Jiralite
2023-12-14 21:15:27 +00:00
committed by GitHub
parent adfd9cd3b3
commit 18c2dccd0e
30 changed files with 225 additions and 1261 deletions

View File

@@ -0,0 +1,64 @@
---
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.

View File

@@ -0,0 +1,64 @@
---
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:
![Successfully created application](/assets/create-app.png)
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:
![Bot application](/assets/bot-user.png)
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>

View File

@@ -0,0 +1,48 @@
---
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:
![Bot Authorization page](/assets/bot-auth-page.png)
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.