discord.js:Bot发送了两次相同的嵌入内容

时间:2020-09-23 15:42:21

标签: javascript node.js discord.js

我对我的discord机器人进行了编程,以使其在键入某些命令时以一条消息进行回复,但是由于某种原因,它发送了相同的嵌入两次。我不知道为什么。这是我的代码:

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

2 个答案:

答案 0 :(得分:1)

它可能正在另一个终端上运行。尝试重新启动PC或找到并关闭该终端。

答案 1 :(得分:0)

此代码对我有用

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