简体   繁体   中英

discord.js: Bot is sending the same embed twice

I programmed my discord bot to reply with a message when i type down a certain command, but for some reason, its sending the same embed twice. I couldn't figure out why. Here's my code:

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

client.on("message", message => {

     if (message.content.toLowerCase().startsWith(prefix + "clear")) {
        message.channel.messages.fetch({limit: 100}).then(messages => {         
        message.channel.bulkDelete(messages)});

        const deleteEmbed = new Discord.MessageEmbed()
        .setColor('#ffd6d6')
        .setTitle('Bot has completed the action of clearing messages.\n')
        .setDescription(`Bot has deleted some messages.`)
        client.channels.cache.get('757945678772305921').send(deleteEmbed); 
    }
}); 

It might be running on another terminal. Try restarting your PC or find and close that terminal.

This Code works for me

client.on('message', message => {
  const args = message.content.slice(prefix.length).split(/ +/);
  const command = args.shift().toLowerCase();
  if (!message.content.startsWith(prefix) || message.author.bot) return;
  if (command.includes('blacklist')) {
    message.react('💯')
    const blacklistEmbed = new Discord.MessageEmbed()
      .setColor('#ffd6d6')
      .setTitle('!Blacklist\n')
      .setDescription('Private Messages\nCheck Your PMs For More Information')
    message.channel.send(blacklistEmbed)
    const blacklist2Embed = new Discord.MessageEmbed()
      .setColor('#ffd6d6')
      .setTitle('!Blacklist\n')
      .addField("Banned Words Are;", profanities)
    message.author.send(blacklist2Embed)
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM