My discord bot is not coming online. Here is my .js file
const Discord = require("discord.js");
const client = new Discord.Client();
const TOKEN = "my-token-is-here";
client.on("message", message => {
if (message.content === "Hello Discord Bot") {
message.channel.send("Hi There!");
}
{
console.log("Bot Is Ready!");
}
});
client.login(TOKEN)
The error I am getting is
SyntaxError: Unexpected token ?
Based on your comments you've installed Discord.js version 13.1.0 but your NodeJS version is lower than 16.6. There are two options for you to solve this problem.
You'll need to update your NodeJS version to 16.6 or higher. You can do this by downloading a version of NodeJS at the NodeJS website and complete the setup again.
Once you've completed the setup you should be able to run your Discord bot again.
If you don't want to update your version you can install Discord.js version 12.5.3. This version is not as stable as version 13.1.0 is but it is possible. You can do this by using the npm command npm install discord.js@12.5.3. After installing the 12.5.3 version you should be able to run your bot again.
Also like Luca Mertens noticed your breaks are incorrectely. You should replace them to
client.on('ready', () => console.log(`Bot is ready`));
client.on("message", message => {
if (message.content === "Hello Discord Bot") {
message.channel.send("Hi There!");
}
});
You should never post any private tokens publicly. Be sure to make a new token on the Discord-Developer-Portal and don't continue using this one!
To your question: It seems like the lines
{
console.log("Bot Is Ready!");
}
cause the syntax error. You probably want to move that statement into it's own event handler for the event "ready" (triggered when DiscordJs has finished setting up the bot-client for you).
client.on("message", message => {
if (message.content === "Hello Discord Bot") {
message.channel.send("Hi There!");
}
});
client.on("ready", () => {
console.log("Bot Is Ready!");
});
client.login(TOKEN)