Skip to main content

Common Issues

This page covers the most frequently encountered problems when running MJ Bot and its dashboard, along with their solutions.


Bot Won't Start

Symptoms: The bot process exits immediately or crashes on startup.

Solutions:

  1. Check your bot token. Make sure DISCORD_TOKEN in your .env file is correct and has not been regenerated in the Discord Developer Portal.

  2. Check the pm2 logs for specific error messages:

    pm2 logs mj-bot --lines 100
  3. Check your Node.js version. MJ Bot requires Node.js 18 or later:

    node -v
tip

If you recently regenerated your bot token in the Discord Developer Portal, make sure you update the .env file and restart the bot with pm2 restart mj-bot.


Database Connection Errors

Symptoms: Errors mentioning "connection refused", "ECONNREFUSED", or "Can't reach database server".

Solutions:

  1. Verify your DATABASE_URL in the .env file. Make sure the hostname, port, username, password, and database name are all correct.

  2. Check if the database service is running:

    # For PostgreSQL
    systemctl status postgresql

    # For MySQL
    systemctl status mysql
  3. Test the connection manually:

    # For PostgreSQL
    psql "$DATABASE_URL"
warning

If you changed your database password, update DATABASE_URL in the .env files for both the bot and the dashboard, then restart both processes.


Dashboard Login Fails

Symptoms: Clicking "Sign in with Discord" results in an error page, a redirect loop, or an "Invalid OAuth2 redirect_uri" message.

Solutions:

  1. Check the redirect URL in the Discord Developer Portal under OAuth2. It must be set to exactly:

    https://your-domain.com/api/auth/callback/discord
  2. Check NEXTAUTH_SECRET. It must be set to a random string of at least 32 characters. Generate one with:

    openssl rand -base64 32
  3. Check DISCORD_CLIENT_ID and DISCORD_CLIENT_SECRET. Make sure they match the values shown in the Discord Developer Portal.

  4. Make sure NEXTAUTH_URL in your .env matches your actual dashboard URL (including https://).

  5. Restart the dashboard after making changes:

    pm2 restart mj-dashboard

Music Not Working

Symptoms: Music commands fail, the bot does not join the voice channel, or playback stops immediately.

Solutions:

  1. Check that Lavalink is running:

    pm2 status

    Look for the Lavalink process. If it is not running, start it:

    pm2 start lavalink
  2. Check the Lavalink configuration in your .env file. Verify that the Lavalink host, port, and password are correct.

  3. Check the Lavalink logs for errors:

    pm2 logs lavalink --lines 50
info

Lavalink requires Java 17 or later. Verify your Java version with java -version.


Bot Is Online but Commands Don't Work

Symptoms: The bot appears online in Discord but does not respond to slash commands.

Solutions:

  1. Slash commands auto-register on startup. If commands are missing, restart the bot to trigger re-registration:

    pm2 restart mj-bot
  2. Check bot permissions. Make sure the bot has the following permissions in your server:

    • Send Messages
    • Use Application Commands
    • Embed Links
    • Attach Files
    • Connect and Speak (for music commands)
  3. Re-invite the bot with the correct permissions if needed. Use the OAuth2 URL generator in the Discord Developer Portal with the bot and applications.commands scopes.

tip

Slash command registration can take up to an hour to propagate globally. If you just started the bot for the first time, wait a bit and try again.


Missing Intents Error

Symptoms: The bot crashes with an error mentioning "disallowed intents" or "privileged intent".

Solution:

  1. Go to the Discord Developer Portal.
  2. Select your application and navigate to the Bot section.
  3. Scroll down to Privileged Gateway Intents.
  4. Enable all three privileged intents:
    • Presence Intent
    • Server Members Intent
    • Message Content Intent
  5. Click Save Changes.
  6. Restart the bot:
    pm2 restart mj-bot
danger

If your bot is in more than 100 servers, you must apply for privileged intent approval through the Discord Developer Portal. Bots in fewer than 100 servers can toggle these intents freely.


Prisma Errors

Symptoms: Errors mentioning "PrismaClientInitializationError", "unknown model", or schema-related issues.

Solutions:

  1. Regenerate the Prisma client:

    npx prisma generate
  2. Push the schema to the database:

    npx prisma db push
  3. If the issue persists, make sure your DATABASE_URL is correct and the database is accessible.

warning

Run these commands in both the bot and dashboard directories if they each have their own Prisma schema.


Port Already in Use

Symptoms: The dashboard fails to start with an error like "EADDRINUSE" or "port 3000 is already in use".

Solutions:

  1. Find what is using the port:

    lsof -i :3000
  2. Kill the process occupying the port:

    kill -9 <PID>

    Replace <PID> with the process ID from the lsof output.

  3. Or change the dashboard port by setting the PORT environment variable:

    PORT=3001 pm2 start "npm start" --name mj-dashboard
tip

If you see a stale pm2 process, clean it up with pm2 delete mj-dashboard before starting a new one.