I started to make a bot for my Discord server, but I'm completely new to it (I have programming skills, but in web development). I made an application on the Discord developer portal, I made a folder on my PC, I created a package.json
file, a main.js
file, installed node.js, installed discord.js, I deployed my bot on a test server, etc. (not in this order but whatever).
Then, following a tutorial from a site, I made this in the index.js
file:
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (message.content === '!ping') {
message.channel.send('Pong.');
}
});
client.login(' I PUTTED MY TOCKEN HERE ');
When I put the command !ping
on the test server I created, the bot remains offline and I don't receive Pong
...
Can you please help me, please?
If the bot does not turn on, that means you did not correctly login or start the bot. Try to define token
like const token = "BOT TOKEN HERE"
, then put client.login(token)
instead of what you have.
If that does not help, also make sure that you did node .
in your terminal, which will start the bot.
So, your whole code should look something like this:
const Discord = require('discord.js');
const client = new Discord.Client();
const token = "bot token here";
client.on('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (message.content === '!ping') {
message.channel.send('Pong.');
}
});
client.login(token);
What is defining
token
as a variable supposed to do?whenever i write discord.js, i always define token as a new variable. I just suggested trying it.
Yeah, but how would it fix OPs problem?
Now it works!!!! Thanks a looot!!!!