How can you check if the bot is being pinged?

I am creating a command that "kills" people. I want the bot to return the message "Ha! You thought! @Author died!" if they ping the bot. (How do I get the Bot to see if it is pinged?) Here is my current code:

const Discord = require('discord.js');
const bot = new Discord.Client();

module.exports = {
  name: 'kill',
  description: 'kills',
  execute(message, args) {
    message.delete({ timeout: 1000 });
    const target = message.mentions.users.first();
    let memberTarget = message.guild.members.cache.get(target.id);

    if (target == bot.user.username)
      return message.channel.send(`HA! SIKE! <@${message.author.id}> died.`);
    message.channel.send(`<@${memberTarget.user.id}> has died!`);
    console.log(`<@${memberTarget.user.id} died.`);
  },
};

142 thoughts on “How can you check if the bot is being pinged?”

  1. I’m impressed, I must say. Seldom do I encounter a blog that’s equally educative and engaging, and let me tell you, you have hit the nail on the head.
    The problem is an issue that not enough people are speaking intelligently
    about. I am very happy that I found this in my hunt
    for something relating to this.

    Reply

Leave a Comment