Skip to main content

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

VariableRequiredDescription
DISCORD_TOKENYesBot token from the Discord Developer Portal. See Bot Token.
CLIENT_IDYesThe bot's application ID, found on the OAuth2 page.
CLIENT_SECRETYesThe OAuth2 client secret, used by the dashboard for login.
GUILD_IDYesThe ID of your main or support server. Used to register developer-only slash commands.
PREFIXNoDefault command prefix. Defaults to ! if not set.
OWNER_IDSYesComma-separated list of Discord user IDs that have full bot owner access.
DATABASE_URLYesPrisma connection string. See Database Setup.
LAVALINK_HOSTNoHostname of your Lavalink server. Defaults to localhost.
LAVALINK_PORTNoPort of your Lavalink server. Defaults to 2333.
LAVALINK_PASSWORDNoPassword for your Lavalink server.
REDIS_URLNoRedis 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

VariableRequiredDescription
NEXTAUTH_URLYesThe public URL where your dashboard is hosted (e.g., https://mj-bot.xyz). Use http://localhost:3000 for local development.
NEXTAUTH_SECRETYesA random string used to encrypt session tokens. Generate one with openssl rand -base64 32.
DISCORD_CLIENT_IDYesSame value as CLIENT_ID in the bot .env.
DISCORD_CLIENT_SECRETYesSame value as CLIENT_SECRET in the bot .env.
DATABASE_URLYesSame 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:

  1. Go to your application in the Developer Portal.
  2. Navigate to OAuth2 > General.
  3. Under Redirects, add your dashboard callback URL:
    https://mj-bot.xyz/api/auth/callback/discord
    For local development, also add:
    http://localhost:3000/api/auth/callback/discord
  4. Click Save Changes.