Justin
Justin

Reputation: 1

Discord Bot outputting nothing client.on('ready')

Basically, when I run node . in my command prompt nothing is outputted.

My code:

const Discord = require("discord.js");

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });

client.on("ready", () => {
    console.log(`Logged in as ${client.user.tag}`);
});
//My key is located here but I've taken it out for obvious reasons
client.login = "key";

Upvotes: 0

Views: 884

Answers (2)

Brandon Torreglosa
Brandon Torreglosa

Reputation: 103

Your following code contains false syntax.

client.login = "key" //Will create errors.
client.login("key") //Will not create errors.

Also, I would recommend you to install dotenv from the npm package database. Its safer and barely needs any coding experience.

Just look at the difference

client.login("key") //Can see your token
require('dotenv').config();
client.login(process.env.key) //Cant see your token unless i see your .env

Just simply install the package running npm i dotenv, then create a file .env and inside that file have your enviromental variables.

key = token

I hope this helped you. Oh also if your bot is on GitHub make sure to add a .gitignore file so it cant be accessed by other users.

//.gitignore file

.env //This is the file you want hidden

Upvotes: 1

Cannicide
Cannicide

Reputation: 4520

client.login = ('key');

If that is how your code looks and isn't just a typo in the question, that is invalid syntax. client.login() is a method. This is how it should look:

client.login('key');

That is most likely your issue.

Upvotes: 5

Related Questions