How do I make a discord bot ping me when it responds?

This is a fantastic feature of Discord bots. You will want to read this, if you already have your bot set up. If you do not have it set up, please check out this article. This is what you should have in your index.js if you completed the last article:
const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => { 
     console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', msg => { 
   if (message.content === 'ping') { 
       message.channel.send('Pong!'); 
    } 
});

client.login('token');
In this article, we will make the bot reply to you. It is very simple. You just need to change this line: message.channel.send('Pong!'); to this: message.reply('Pong!'); So your file should look like this:
const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', msg => {
   if (message.content === 'ping') {
      message.reply('Pong!');
   }
});

client.login('token');
Now you want to test your bot. Save the file. Run it by using node index.js and then say ping in your server and the bot should reply to you. Congrats!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.