Configuration
MJ Bot uses .env files to store sensitive configuration. You need one for the bot and one for the dashboard.
Bot Environment Variables
Create a .env file in the bot directory:
cp bot/.env.example bot/.env
If no example file exists, create bot/.env manually and add the following:
bot/.env
# Discord
DISCORD_TOKEN=your-bot-token-here
CLIENT_ID=your-application-client-id
CLIENT_SECRET=your-oauth2-client-secret
GUILD_ID=your-support-server-id
# Bot Settings
PREFIX=!
OWNER_IDS=123456789012345678,987654321098765432
# Database
DATABASE_URL=postgresql://mjbot:password@localhost:5432/mjbot
# Lavalink (Music)
LAVALINK_HOST=localhost
LAVALINK_PORT=2333
LAVALINK_PASSWORD=youshallnotpass
# Redis (Optional)
REDIS_URL=redis://localhost:6379
Variable Reference
| Variable | Required | Description |
|---|---|---|
DISCORD_TOKEN | Yes | Bot token from the Discord Developer Portal. See Bot Token. |
CLIENT_ID | Yes | The bot's application ID, found on the OAuth2 page. |
CLIENT_SECRET | Yes | The OAuth2 client secret, used by the dashboard for login. |
GUILD_ID | Yes | The ID of your main or support server. Used to register developer-only slash commands. |
PREFIX | No | Default command prefix. Defaults to ! if not set. |
OWNER_IDS | Yes | Comma-separated list of Discord user IDs that have full bot owner access. |
DATABASE_URL | Yes | Prisma connection string. See Database Setup. |
LAVALINK_HOST | No | Hostname of your Lavalink server. Defaults to localhost. |
LAVALINK_PORT | No | Port of your Lavalink server. Defaults to 2333. |
LAVALINK_PASSWORD | No | Password for your Lavalink server. |
REDIS_URL | No | Redis connection URL for optional caching. |
warning
Never commit .env files to version control. Make sure .env is listed in your .gitignore.
Dashboard Environment Variables
Create a .env file in the dashboard directory:
cp dashboard/.env.example dashboard/.env
If no example file exists, create dashboard/.env manually:
dashboard/.env
# NextAuth
NEXTAUTH_URL=https://mj-bot.xyz
NEXTAUTH_SECRET=generate-a-random-secret-string-here
# Discord OAuth2
DISCORD_CLIENT_ID=your-application-client-id
DISCORD_CLIENT_SECRET=your-oauth2-client-secret
# Database
DATABASE_URL=postgresql://mjbot:password@localhost:5432/mjbot
Variable Reference
| Variable | Required | Description |
|---|---|---|
NEXTAUTH_URL | Yes | The public URL where your dashboard is hosted (e.g., https://mj-bot.xyz). Use http://localhost:3000 for local development. |
NEXTAUTH_SECRET | Yes | A random string used to encrypt session tokens. Generate one with openssl rand -base64 32. |
DISCORD_CLIENT_ID | Yes | Same value as CLIENT_ID in the bot .env. |
DISCORD_CLIENT_SECRET | Yes | Same value as CLIENT_SECRET in the bot .env. |
DATABASE_URL | Yes | Same Prisma connection string used by the bot. |
tip
Generate a secure NEXTAUTH_SECRET by running:
openssl rand -base64 32
Discord OAuth2 Redirect
For the dashboard login to work, you must add a redirect URL in the Discord Developer Portal:
- Go to your application in the Developer Portal.
- Navigate to OAuth2 > General.
- Under Redirects, add your dashboard callback URL:
For local development, also add:
https://mj-bot.xyz/api/auth/callback/discordhttp://localhost:3000/api/auth/callback/discord - Click Save Changes.