Warm tip: This article is reproduced from serverfault.com, please click

Discord bot is not responding to commands

发布于 2020-11-28 14:51:31

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?

Questioner
SCRACK
Viewed
0
6,449 2021-01-26 02:50:51

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