Discord bot deployment fails on Heroku with CLIENT_MISSING_INTENTS error

My Discord bot crashes immediately after starting on Heroku with a CLIENT_MISSING_INTENTS error. Here’s what I see in the logs:

2021-08-15T11:25:42.158234+00:00 heroku[worker.1]: Starting process with command `node index.js`
2021-08-15T11:25:42.842156+00:00 heroku[worker.1]: State changed from starting to up
2021-08-15T11:25:45.234891+00:00 heroku[worker.1]: Process exited with status 1
2021-08-15T11:25:45.298445+00:00 heroku[worker.1]: State changed from up to crashed
2021-08-15T11:25:45.156773+00:00 app[worker.1]: /app/node_modules/discord.js/src/client/Client.js:544
2021-08-15T11:25:45.156789+00:00 app[worker.1]:       throw new TypeError('CLIENT_MISSING_INTENTS');
2021-08-15T11:25:45.156790+00:00 app[worker.1]:       ^
2021-08-15T11:25:45.156790+00:00 app[worker.1]: 
2021-08-15T11:25:45.156791+00:00 app[worker.1]: TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
2021-08-15T11:25:45.156791+00:00 app[worker.1]:     at Client._validateOptions (/app/node_modules/discord.js/src/client/Client.js:544:13)
2021-08-15T11:25:45.156792+00:00 app[worker.1]:     at new Client (/app/node_modules/discord.js/src/client/Client.js:73:10)
2021-08-15T11:25:45.156792+00:00 app[worker.1]:     at Object.DiscordBot.createBot (/app/index.js:41:15)
2021-08-15T11:25:45.156793+00:00 app[worker.1]:     at Object.DiscordBot.start (/app/index.js:28:9)
2021-08-15T11:25:45.156793+00:00 app[worker.1]:     at Object.<anonymous> (/app/index.js:1205:7)

The bot works fine locally but keeps crashing on Heroku. What could be causing this intents error during deployment?

You’re using Discord.js v13 or later, which needs explicit intents. Your Client constructor is missing the intents parameter. Fix it by adding intents to your client setup: new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] }) - adjust based on what your bot actually does. Even though it works locally, Heroku might be using cached dependencies. Check that your index.js imports the required intents and passes them to the Client constructor. Also, if you’re using MESSAGE_CONTENT or similar intents, make sure they’re enabled in the Discord Developer Portal.

sounds like a discord.js version mismatch. newer versions need you to specify intents when creating the client. check if heroku’s running a different discord.js version than your local setup - your package.json might have ^ or ~ that’s pulling newer versions on deploy

Check your Heroku environment variables - this usually means your bot token isn’t set up right in production. Same thing happened to me. Bot worked fine locally but kept crashing on Heroku because I forgot to add the environment variables in the dashboard. Make sure DISCORD_TOKEN is set in your Config Vars section. Also double-check that your Procfile points to the right main file. That intents error can be misleading - it’s probably just an auth failure from missing config.