codea.live
Search…
Config
A guide on how to configure 2PG - Simple, powerful Discord bot, for your projects needs, and an explanation on what each environment variable means.

.env

This is the .env file template. Copy this text into the file, and customize according to your needs.

Template

Development
Testing
Live
This template would go in the root project folder, and is used for the main application.
Port 3000 is commonly used by many Node.js applications. Port 4200 is for the dashboard, running on an Angular development server.
.env
1
API_URL="http://localhost:3000/api"
2
BOT_TOKEN=""
3
CLIENT_ID=""
4
CLIENT_SECRET=""
5
DASHBOARD_URL="http://localhost:4200"
6
DBOTS_AUTH=""
7
FEEDBACK_CHANNEL_ID=""
8
GUILD_ID=""
9
OWNER_ID=""
10
MONGO_URI="mongodb://localhost/2PG"
11
PAYPAL_MODE="sandbox"
12
PAYPAL_CLIENT_ID=""
13
PAYPAL_SECRET=""
14
PORT="3000"
15
PREMIUM_ROLE_ID=""
16
TOP_GG_AUTH=""
17
VOTE_CHANNEL_ID="788001309197860874"
Copied!
This template would go in the test/ directory, and is used for testing.
A different port is used for the API to allow the integration tests to work indendently from the main application. A separate database is also used for this purpose.
test/.env
1
API_URL="http://localhost:3001/api"
2
BOT_ID=""
3
BOT_TOKEN=""
4
CLIENT_SECRET=""
5
DASHBOARD_URL="http://localhost:4200"
6
DBOTS_AUTH=""
7
FEEDBACK_CHANNEL_ID=""
8
GUILD_ID=""
9
OWNER_ID=""
10
MONGO_URI="mongodb://localhost/2PG-Test"
11
PORT="3001"
12
PREMIUM_ROLE_ID=""
13
STRIPE_SECRET_KEY=""
14
STRIPE_WEBHOOK_SECRET=""
15
TOP_GG_AUTH=""
16
VOTE_CHANNEL_ID="788001309197860874"
Copied!
This template assumes you are deploying 2PG live, and for non development purposes. Replace placeholder values according to your project's needs.
.env
1
API_URL="https://example.com/api"
2
BOT_ID=""
3
BOT_TOKEN=""
4
CLIENT_SECRET=""
5
DASHBOARD_URL="https://example.com"
6
DBOTS_AUTH=""
7
FEEDBACK_CHANNEL_ID=""
8
GUILD_ID=""
9
OWNER_ID=""
10
MONGO_URI="mongodb://localhost/2PG"
11
PAYPAL_MODE="live"
12
PAYPAL_CLIENT_ID=""
13
PAYPAL_SECRET=""
14
PORT="3000"
15
PREMIUM_ROLE_ID=""
16
TOP_GG_AUTH=""
17
VOTE_CHANNEL_ID="788001309197860874"
Copied!
.env should not be saved with Git. This would expose all of your tokens. By default, this file is added to .gitignore, which means Git should not commit this file.

How do I get these values?

The bot values are found at the Discord Developer Portal. These are required for the bot to login and function correctly.
Discord Developer Portal — API Docs for Bots and Developers
Discord Developer Portal
Discord Developer Portal
Developer mode needs to be enabled, in Discord settings, to get some of these values.
Discord Developer Mode

Required Variables

API_URL

The API URL is used to get XP cards via commands, and more. It is also used in API routes for various functions.
API Root Route

CLIENT_ID

The Bot ID is used for logging into the dashboard (Discord OAuth2), and is used to build the authorization URL.
Discord Client ID

BOT_TOKEN

This is the actual bot token, that allows you to login the bot user using the Discord API. It is used for logging in the bot, and interacting with the Discord API.
The bot token is found at the Discord Developer Portal

CLIENT_SECRET

The client secret is used for logging in with Discord OAuth2. It lets Discord know that they can trust our application.
Discord Client Secret

DASHBOARD_URL

The dashboard URL refers to the local, or deployment website. If you were developing locally with the Dashboard Project it would be http://localhost:4200, by default. If you are deploying this live, you would use the URL of the website home page. It's used for API redirects, commands, and more.
Website Home Page

MONGO_URI

The mongo URI is used for connecting to the MongoDB database. It should follow the MongoDB URI string format. The database is used for customizing guilds, saving user XP, and much more.
Connection String URI Format
mongodb

PORT

The port is used serving the API. Port 3000 is commonly used with Node.js apps and is used with 2PG, by default. If you use port 80, and it's not blocked by another process (e.g. NginX), it should host your dashboard by default when you connect to the server IP.
2PG.xyz uses port 443 with NginX

Optional Variables

OWNER_ID

The owner ID refers to your Discord user ID. It is used for getting bot stats, but is not required for 2PG to function.
Developer Mode needs to be enabled to copy a User ID in Discord.
Get a Discord User ID

PAYPAL_CLIENT_ID

Client ID of the PayPal secret, from the PayPal developers website.

PAYPAL_MODE

Should be either sandbox, for development, or live, for live payments.

PAYPAL_SECRET

Client Secret (hidden - above) from the PayPal developers website.

TOP_GG_AUTH

Webhook secret from top.gg Discord bot list.
Last modified 7mo ago