Setting up your project environment variables - chicklightning/tcg-pocket-trading-bot GitHub Wiki
Now we'll want to set up the environment variables for our project so that when we run the bot, it knows how to connect to our database and has the correct credentials to talk to Discord servers.
Create .env file
- Navigate in File Explorer to the folder where you saved the code from this repository.
- In the root directory of this folder (so probably something like
C:\Users\...\tcg-pocket-trading-bot
), create a file called ".env" (without the quotation marks)
This is the file where we will store all of our important environment variables. If you ever decide to save your code to your own repository online using Git, the .gitignore file for this code will automatically screen out this file so you don't risk uploading anything that should be kept secret.
Grab Discord token and client ID
- Grab your Discord bot token (as described in this tutorial) or generate a new token and save it somewhere
- In your .env file, add the text
DISCORD_TOKEN=
- Copy-paste the token from step 1 after the "=" sign on this same line
- Grab your Discord application's client ID by navigating back to the Developer Portal, going to the "OAuth2" tab on the left side, and choosing to "Copy" your client ID (see image below)
- On a new line in your .env file, add the text
CLIENT_ID=
- Copy-paste your client ID from step 4 after the "=" on this same line
This information lets us connect to Discord's API and send and receive information from users via the app, as well as registering our commands.
Add Postgres connection information
- In your .env file, add a new line with the text
DEV_DATABASE_URL=
- After the "=" on the same line, add
postgres://username:[email protected]:5432/tcg-pocket-dev
- Replace "username" with the username of the user that owns your tcg-pocket-dev database, likely "postgres" if you followed this guide
- Replace "password" with the superuser password for the "postgres" user, or whichever user you picked to own this database
- On a new line, add the text
NODE_ENV=dev
so we know to connect to the development environment database (the database set up during this tutorial) - Save your .env file
Next steps
Next, we'll finish setting up everything for the bot and run it for the first time!