I got this error message on heroku and I'm not sure how to fix it, since my code is very basic. I've been following a tutorial on how to set my discord bot up 24/7. If anyone can help me fix this, much appreciated! :)
const Discord = require('discord.js');
const bot = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Discord.Intents.FLAGS.DIRECT_MESSAGES
]
});
bot.on("ready", function () {
console.log("Hello!");
});
bot.login(process.env.token);
Above is my code in index.js and below is package.json
{
"name": "discordbot",
"version": "1.0.0",
"engines": {
"node": ">=16.11.0"
},
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"discord.js": "^13.2.0",
"dotenv": "^10.0.0"
}
}
console.log(process.env.token)
to see if you really are able to get the token.require('dotenv').config()
to load your env variables intoprocess.env
before trying to use them, since you're usingdotenv
.