Discord bot is not responding to commands

Viewed 6444

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?

2 Answers

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);

Make sure that your bot is allowed to recieve messages (discord.com/developers > your bot > bot > the two intent-switches).

Then add this into the brackets of new Discord.Client(); { partials: ['MESSAGE', 'CHANNEL', 'REACTION', 'USER', 'GUILD_MEMBER']} (you can remove some of those parameters but message will be needed).

Sorry for bad English...

Related